From 77a3a95ed501dc0b0c731c27e492746a92d3c79c Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Thu, 23 Jul 2026 15:20:42 +0200 Subject: [PATCH] [IMP] queue_job: add MaxRetryJobError Prior to this change it was impossible to catch the specific case of max retry error w/o ispecting the attributes of the exception. --- queue_job/exception.py | 4 ++++ queue_job/job.py | 4 ++-- test_queue_job/tests/test_job.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/queue_job/exception.py b/queue_job/exception.py index c04bc8f0cf..f6ced612c1 100644 --- a/queue_job/exception.py +++ b/queue_job/exception.py @@ -18,6 +18,10 @@ class FailedJobError(JobError): """A job had an error having to be resolved.""" +class MaxRetryJobError(FailedJobError): + """A job has hit its maximum number of retries and failed.""" + + class RetryableJobError(JobError): """A job had an error but can be retried. diff --git a/queue_job/job.py b/queue_job/job.py index 032bdb9339..191a07fb97 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -14,7 +14,7 @@ import odoo -from .exception import FailedJobError, NoSuchJobError, RetryableJobError +from .exception import MaxRetryJobError, NoSuchJobError, RetryableJobError WAIT_DEPENDENCIES = "wait_dependencies" PENDING = "pending" @@ -500,7 +500,7 @@ def perform(self): # change the exception type but keep the original # traceback and message: # http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/ - new_exc = FailedJobError( + new_exc = MaxRetryJobError( "Max. retries (%d) reached: %s" % (self.max_retries, value or type_) ) raise new_exc from err diff --git a/test_queue_job/tests/test_job.py b/test_queue_job/tests/test_job.py index 4d771f5516..d5f866a2dc 100644 --- a/test_queue_job/tests/test_job.py +++ b/test_queue_job/tests/test_job.py @@ -10,7 +10,7 @@ from odoo.addons.queue_job import identity_exact from odoo.addons.queue_job.delay import DelayableGraph from odoo.addons.queue_job.exception import ( - FailedJobError, + MaxRetryJobError, NoSuchJobError, RetryableJobError, ) @@ -77,7 +77,7 @@ def test_retryable_error(self): with self.assertRaises(RetryableJobError): test_job.perform() self.assertEqual(test_job.retry, 2) - with self.assertRaises(FailedJobError): + with self.assertRaises(MaxRetryJobError): test_job.perform() self.assertEqual(test_job.retry, 3)