diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b1cd6d9751..d9df375fac 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -4,7 +4,6 @@ exclude: |
^base_import_async/|
^queue_job_batch/|
^queue_job_cron/|
- ^queue_job_cron_jobrunner/|
^test_queue_job_batch/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
diff --git a/queue_job_cron_jobrunner/README.rst b/queue_job_cron_jobrunner/README.rst
index 8615285dec..0b41ea48d7 100644
--- a/queue_job_cron_jobrunner/README.rst
+++ b/queue_job_cron_jobrunner/README.rst
@@ -21,13 +21,13 @@ Queue Job Cron Jobrunner
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
- :target: https://github.com/OCA/queue/tree/18.0/queue_job_cron_jobrunner
+ :target: https://github.com/OCA/queue/tree/19.0/queue_job_cron_jobrunner
:alt: OCA/queue
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_cron_jobrunner
+ :target: https://translation.odoo-community.org/projects/queue-19-0/queue-19-0-queue_job_cron_jobrunner
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=19.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -102,7 +102,7 @@ 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
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -142,6 +142,6 @@ Current `maintainer `__:
|maintainer-ivantodorovich|
-This module is part of the `OCA/queue `_ project on GitHub.
+This module is part of the `OCA/queue `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/queue_job_cron_jobrunner/__manifest__.py b/queue_job_cron_jobrunner/__manifest__.py
index c61918262d..dad4881789 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": "18.0.1.0.1",
+ "version": "19.0.1.0.0",
"development_status": "Alpha",
"author": "Camptocamp SA, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
@@ -13,5 +13,5 @@
"data/ir_cron.xml",
"views/ir_cron.xml",
],
- "installable": False,
+ "installable": True,
}
diff --git a/queue_job_cron_jobrunner/models/queue_job.py b/queue_job_cron_jobrunner/models/queue_job.py
index 3213d28d0b..fc9095d10d 100644
--- a/queue_job_cron_jobrunner/models/queue_job.py
+++ b/queue_job_cron_jobrunner/models/queue_job.py
@@ -17,6 +17,9 @@
_logger = logging.getLogger(__name__)
+# Delay of a RetryableJobError without seconds nor retry pattern
+RETRY_SECONDS = 5
+
class QueueJob(models.Model):
_inherit = "queue.job"
@@ -76,8 +79,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/newsfragments/1023.bugfix b/queue_job_cron_jobrunner/readme/newsfragments/1023.bugfix
new file mode 100644
index 0000000000..054817d90c
--- /dev/null
+++ b/queue_job_cron_jobrunner/readme/newsfragments/1023.bugfix
@@ -0,0 +1 @@
+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 9efaba8690..44a07ec12e 100644
--- a/queue_job_cron_jobrunner/static/description/index.html
+++ b/queue_job_cron_jobrunner/static/description/index.html
@@ -374,7 +374,7 @@ Queue Job Cron Jobrunner
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3c8052bb9647ac1c2222b7bbe43133884ab314534ef09686a3aef58e6b38f712
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

This module implements a simple queue.job runner using ir.cron
triggers.
It’s meant to be used on environments where the regular job runner can’t
@@ -446,7 +446,7 @@
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
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
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")
+ )