changeset 5d3eafccb4d1 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=5d3eafccb4d1
description:
Reschedule task failing for operational errors
We should always try to execute them later as operational errors should
be
temporary.
issue9252
review319301002
diffstat:
trytond/worker.py | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diffs (29 lines):
diff -r 281a06c0e740 -r 5d3eafccb4d1 trytond/worker.py
--- a/trytond/worker.py Sat Apr 25 23:39:43 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
@@ -117,5 +119,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)