diff --git a/queue_job_cron_jobrunner/README.rst b/queue_job_cron_jobrunner/README.rst index 2b65b45356..02510698ac 100644 --- a/queue_job_cron_jobrunner/README.rst +++ b/queue_job_cron_jobrunner/README.rst @@ -96,6 +96,21 @@ Known issues / Roadmap - Commit transaction after job state updated to started. (See ``_process``) +Changelog +========= + +20.0.1.0.1 (2026-10-15) +----------------------- + +Bugfixes +~~~~~~~~ + +- A job raising ``RetryableJobError(seconds=N)`` is now postponed by + ``N`` seconds, and without ``seconds`` the retry pattern of the job + function applies, as with the standard job runner. Before, the cron + runner always postponed it by 5 seconds (still the delay when neither + is set). + Bug Tracker =========== diff --git a/queue_job_cron_jobrunner/__manifest__.py b/queue_job_cron_jobrunner/__manifest__.py index 90bcf9332d..071a2e9ae6 100644 --- a/queue_job_cron_jobrunner/__manifest__.py +++ b/queue_job_cron_jobrunner/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Queue Job Cron Jobrunner", "summary": "Run jobs without a dedicated JobRunner", - "version": "20.0.1.0.0", + "version": "20.0.1.0.1", "development_status": "Alpha", "author": "Camptocamp SA, Odoo Community Association (OCA)", "maintainers": ["ivantodorovich"], diff --git a/queue_job_cron_jobrunner/models/queue_job.py b/queue_job_cron_jobrunner/models/queue_job.py index 4946e29075..7bbd3490ce 100644 --- a/queue_job_cron_jobrunner/models/queue_job.py +++ b/queue_job_cron_jobrunner/models/queue_job.py @@ -19,6 +19,9 @@ _logger = logging.getLogger(__name__) +# Delay of a RetryableJobError without seconds nor retry pattern +RETRY_SECONDS = 5 + class QueueJob(models.Model): _inherit = "queue.job" @@ -78,8 +81,13 @@ def _process(self, commit=False): _logger.debug("%s OperationalError, postponed", job) except RetryableJobError as err: - # delay the job later, requeue - job.postpone(result=str(err), seconds=5) + # delay the job later, requeue: as in queue_job's controller, honour + # the seconds of the exception, then the retry pattern of the job + # function; without both, keep the short delay of the cron runner + seconds = err.seconds + if not seconds and not job.job_config.retry_pattern: + seconds = RETRY_SECONDS + job.postpone(result=str(err), seconds=seconds) job.set_pending(reset_retry=False) job.store() _logger.debug("%s postponed", job) diff --git a/queue_job_cron_jobrunner/readme/HISTORY.md b/queue_job_cron_jobrunner/readme/HISTORY.md new file mode 100644 index 0000000000..6f101cff9d --- /dev/null +++ b/queue_job_cron_jobrunner/readme/HISTORY.md @@ -0,0 +1,8 @@ +## 20.0.1.0.1 (2026-10-15) + +### Bugfixes + +- A job raising `RetryableJobError(seconds=N)` is now postponed by `N` + seconds, and without `seconds` the retry pattern of the job function + applies, as with the standard job runner. Before, the cron runner always + postponed it by 5 seconds (still the delay when neither is set). diff --git a/queue_job_cron_jobrunner/static/description/index.html b/queue_job_cron_jobrunner/static/description/index.html index 1239966941..80109eacc2 100644 --- a/queue_job_cron_jobrunner/static/description/index.html +++ b/queue_job_cron_jobrunner/static/description/index.html @@ -401,11 +401,18 @@

Queue Job Cron Jobrunner

+
+

Changelog

+
+

20.0.1.0.1 (2026-10-15)

+
+

Bugfixes

+
    +
  • A job raising RetryableJobError(seconds=N) is now postponed by +N seconds, and without seconds the retry pattern of the job +function applies, as with the standard job runner. Before, the cron +runner always postponed it by 5 seconds (still the delay when neither +is set).
  • +
+
+
+
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -450,15 +473,15 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association diff --git a/queue_job_cron_jobrunner/tests/test_queue_job.py b/queue_job_cron_jobrunner/tests/test_queue_job.py index 54800b792c..45b7ee31d4 100644 --- a/queue_job_cron_jobrunner/tests/test_queue_job.py +++ b/queue_job_cron_jobrunner/tests/test_queue_job.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from datetime import timedelta +from unittest.mock import patch from freezegun import freeze_time @@ -10,6 +11,8 @@ from odoo.tests.common import TransactionCase from odoo.tools import mute_logger +from odoo.addons.queue_job.exception import RetryableJobError + class TestQueueJob(TransactionCase): @classmethod @@ -97,3 +100,46 @@ def test_acquire_one_job_consume_the_oldest_first(self): self.env["res.partner"].with_delay(priority=30).create({"name": "test"}) self.assertEqual(self.env["queue.job"]._acquire_one_job(), job.db_record()) + + def _run_retryable_job(self, seconds=None, retry_pattern=None): + """Process a job raising RetryableJobError as the cron runner does""" + if retry_pattern: + self.env["queue.job.function"].create( + {"name": ".create", "retry_pattern": retry_pattern} + ) + job = self.env["res.partner"].with_delay().create({"name": "test"}) + job_record = job.db_record() + partner_model = type(self.env["res.partner"]) + + def create(self, vals_list): + raise RetryableJobError("Try again later", seconds=seconds) + + with ( + freeze_time("2022-02-22 22:22:22"), + patch.object(partner_model, "create", create), + ): + job_record._process(commit=False) + self.assertEqual(job_record.state, "pending") + self.assertEqual(job_record.retry, 1) + return job_record + + def test_queue_job_retryable_error_seconds(self): + """RetryableJobError(seconds=N) postpones the job by N seconds""" + job_record = self._run_retryable_job(seconds=120) + self.assertEqual( + job_record.eta, fields.Datetime.to_datetime("2022-02-22 22:24:22") + ) + + def test_queue_job_retryable_error_retry_pattern(self): + """Without seconds, the retry pattern of the job function applies""" + job_record = self._run_retryable_job(retry_pattern={1: 300}) + self.assertEqual( + job_record.eta, fields.Datetime.to_datetime("2022-02-22 22:27:22") + ) + + def test_queue_job_retryable_error_default(self): + """Without seconds or retry pattern, the job is postponed by 5 seconds""" + job_record = self._run_retryable_job() + self.assertEqual( + job_record.eta, fields.Datetime.to_datetime("2022-02-22 22:22:27") + )