changeset 022f4f894353 in trytond:5.0 details: https://hg.tryton.org/trytond?cmd=changeset;node=022f4f894353 description: Reschedule task failing for operational errors
We should always try to execute them later as operational errors should be temporary. issue9252 review319301002 (grafted from 5d3eafccb4d148bd0df1389a405e4ff36c08121b) diffstat: trytond/worker.py | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diffs (29 lines): diff -r 04a96436996f -r 022f4f894353 trytond/worker.py --- a/trytond/worker.py Fri May 01 15:15:32 2020 +0200 +++ b/trytond/worker.py Tue Apr 28 00:28:06 2020 +0200 @@ -1,6 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +import datetime as dt import logging +import random import select import signal import time @@ -111,5 +113,16 @@ continue raise logger.info('task "%d" done', task_id) + except backend.DatabaseOperationalError: + try: + with Transaction().start(pool.database_name, 0) as transaction: + task = Queue(task_id) + scheduled_at = dt.datetime.now() + scheduled_at += dt.timedelta( + seconds=random.randint(0, 2 ** retry)) + Queue.push(task.name, task.data, scheduled_at=scheduled_at) + except Exception: + logger.critical( + 'rescheduling task "%d" failed', task_id, exc_info=True) except Exception: logger.critical('task "%d" failed', task_id, exc_info=True)