From deeb21b62d9e0ba382f6b6f7cfc56cd4fa56e279 Mon Sep 17 00:00:00 2001 From: Wolfgang Pichler Date: Thu, 19 Nov 2020 08:16:47 +0100 Subject: [PATCH 1/2] Fix missing rollback on retried jobs When RetryableJobError was raised, any change done by the job was not rollbacked. Using `raise` would throw the exception up to the core and rollback, but we would have a stack trace in the logs for each try. Calling rollback manually (rollback also clears the env) hide the tracebacks, however, when the last try fails, the full traceback is still shown in the logs. Fixes #261 --- queue_job/controllers/main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/queue_job/controllers/main.py b/queue_job/controllers/main.py index f9f2206b2b..68aba17ab8 100644 --- a/queue_job/controllers/main.py +++ b/queue_job/controllers/main.py @@ -89,9 +89,11 @@ def retry_postpone(job, message, seconds=None): if err.pgcode not in PG_CONCURRENCY_ERRORS_TO_RETRY: raise - retry_postpone(job, tools.ustr(err.pgerror, errors='replace'), - seconds=PG_RETRY) _logger.debug('%s OperationalError, postponed', job) + raise RetryableJobError( + tools.ustr(err.pgerror, errors='replace'), + seconds=PG_RETRY + ) except NothingToDoJob as err: if str(err): @@ -106,6 +108,10 @@ def retry_postpone(job, message, seconds=None): # delay the job later, requeue retry_postpone(job, str(err), seconds=err.seconds) _logger.debug('%s postponed', job) + # Do not trigger the error up because we don't want an exception + # traceback in the logs we should have the traceback when all + # retries are exhausted + env.cr.rollback() except (FailedJobError, Exception): buff = StringIO() From a5028fb79f67215a23417bc147cfdd6777a88bfa Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 10 Feb 2021 12:01:51 +0100 Subject: [PATCH 2/2] Fix date_done set when state changes back to pending When Job.date_done has been set, for instance because the job has been performed, if the job is set back to pending (e.g. a RetryableJobError is raised), the date_done is kept. --- queue_job/job.py | 1 + 1 file changed, 1 insertion(+) diff --git a/queue_job/job.py b/queue_job/job.py index 53aa81e118..66d82f865e 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -594,6 +594,7 @@ def set_pending(self, result=None, reset_retry=True): self.state = PENDING self.date_enqueued = None self.date_started = None + self.date_done = None if reset_retry: self.retry = 0 if result is not None: