Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions queue_job_cron_jobrunner/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========

Expand Down
2 changes: 1 addition & 1 deletion queue_job_cron_jobrunner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
12 changes: 10 additions & 2 deletions queue_job_cron_jobrunner/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions queue_job_cron_jobrunner/readme/HISTORY.md
Original file line number Diff line number Diff line change
@@ -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).
43 changes: 33 additions & 10 deletions queue_job_cron_jobrunner/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,18 @@ <h1>Queue Job Cron Jobrunner</h1>
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-3">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-4">20.0.1.0.1 (2026-10-15)</a><ul>
<li><a class="reference internal" href="#bugfixes" id="toc-entry-5">Bugfixes</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-6">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-7">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-8">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-9">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -441,24 +448,40 @@ <h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<tt class="docutils literal">_process</tt>)</li>
</ul>
</div>
<div class="section" id="changelog">
<h2><a class="toc-backref" href="#toc-entry-3">Changelog</a></h2>
<div class="section" id="section-1">
<h3><a class="toc-backref" href="#toc-entry-4">20.0.1.0.1 (2026-10-15)</a></h3>
<div class="section" id="bugfixes">
<h4><a class="toc-backref" href="#toc-entry-5">Bugfixes</a></h4>
<ul class="simple">
<li>A job raising <tt class="docutils literal">RetryableJobError(seconds=N)</tt> is now postponed by
<tt class="docutils literal">N</tt> seconds, and without <tt class="docutils literal">seconds</tt> 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).</li>
</ul>
</div>
</div>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/queue/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron_jobrunner%0Aversion:%2020.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Credits</a></h2>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h3><a class="toc-backref" href="#toc-entry-8">Authors</a></h3>
<ul class="simple">
<li>Camptocamp SA</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h3><a class="toc-backref" href="#toc-entry-9">Contributors</a></h3>
<ul>
<li><p class="first"><a class="reference external" href="https://www.camptocamp.com">Camptocamp</a></p>
<blockquote>
Expand All @@ -470,7 +493,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h3><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h3>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
46 changes: 46 additions & 0 deletions queue_job_cron_jobrunner/tests/test_queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
# 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

from odoo import fields
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger

from odoo.addons.queue_job.exception import RetryableJobError


class TestQueueJob(TransactionCase):
@classmethod
Expand Down Expand Up @@ -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": "<res.partner>.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")
)
Loading