From 5991cd65882e3405a46c256792373b4f77fa0055 Mon Sep 17 00:00:00 2001 From: Stefan Wiselka Date: Thu, 28 Aug 2025 12:48:28 +0200 Subject: [PATCH 1/2] [FIX] queue_job_cron_jobrunner: use priority to select job --- queue_job_cron_jobrunner/models/queue_job.py | 4 +-- .../tests/test_queue_job.py | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/queue_job_cron_jobrunner/models/queue_job.py b/queue_job_cron_jobrunner/models/queue_job.py index 28ed243e7c..3213d28d0b 100644 --- a/queue_job_cron_jobrunner/models/queue_job.py +++ b/queue_job_cron_jobrunner/models/queue_job.py @@ -36,7 +36,7 @@ def _acquire_one_job(self): FROM queue_job WHERE state = 'pending' AND (eta IS NULL OR eta <= (now() AT TIME ZONE 'UTC')) - ORDER BY date_created DESC + ORDER BY priority, date_created LIMIT 1 FOR NO KEY UPDATE SKIP LOCKED """ ) @@ -55,7 +55,7 @@ def _process(self, commit=False): # while the job is processing. However, doing this will release the # lock on the db, so we need to find another way. # if commit: - # self.flush() + # self.env.flush_all() # self.env.cr.commit() # Actual processing diff --git a/queue_job_cron_jobrunner/tests/test_queue_job.py b/queue_job_cron_jobrunner/tests/test_queue_job.py index 3f2e0ef637..54800b792c 100644 --- a/queue_job_cron_jobrunner/tests/test_queue_job.py +++ b/queue_job_cron_jobrunner/tests/test_queue_job.py @@ -67,5 +67,33 @@ def test_queue_job_cron_trigger_enqueue_dependencies(self): self.assertEqual(job_record.state, "done", "Processed OK") # if the state is "waiting_dependencies", it means the "enqueue_waiting()" - # step has not been doen when the parent job has been done + # step has not been done when the parent job has been done self.assertEqual(job_record_depends.state, "done", "Processed OK") + + def test_acquire_one_job_use_priority(self): + with freeze_time("2024-01-01 10:01:01"): + self.env["res.partner"].with_delay(priority=3).create({"name": "test"}) + + with freeze_time("2024-01-01 10:02:01"): + job = ( + self.env["res.partner"].with_delay(priority=1).create({"name": "test"}) + ) + + with freeze_time("2024-01-01 10:03:01"): + self.env["res.partner"].with_delay(priority=2).create({"name": "test"}) + + self.assertEqual(self.env["queue.job"]._acquire_one_job(), job.db_record()) + + def test_acquire_one_job_consume_the_oldest_first(self): + with freeze_time("2024-01-01 10:01:01"): + job = ( + self.env["res.partner"].with_delay(priority=30).create({"name": "test"}) + ) + + with freeze_time("2024-01-01 10:02:01"): + self.env["res.partner"].with_delay(priority=30).create({"name": "test"}) + + with freeze_time("2024-01-01 10:03:01"): + self.env["res.partner"].with_delay(priority=30).create({"name": "test"}) + + self.assertEqual(self.env["queue.job"]._acquire_one_job(), job.db_record()) From a6520d990deb4cc8944ed12c8e2a4574a646b708 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Tue, 2 Sep 2025 11:22:22 +0000 Subject: [PATCH 2/2] [BOT] post-merge updates --- README.md | 2 +- queue_job_cron_jobrunner/README.rst | 8 +++-- queue_job_cron_jobrunner/__manifest__.py | 2 +- .../static/description/index.html | 30 +++++++++++-------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6ee699bfd9..46eb74c582 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ addon | version | maintainers | summary [queue_job](queue_job/) | 18.0.1.7.2 | guewen | Job Queue [queue_job_batch](queue_job_batch/) | 18.0.1.0.0 | | Job Queue Batch [queue_job_cron](queue_job_cron/) | 18.0.1.1.1 | | Scheduled Actions as Queue Jobs -[queue_job_cron_jobrunner](queue_job_cron_jobrunner/) | 18.0.1.0.0 | ivantodorovich | Run jobs without a dedicated JobRunner +[queue_job_cron_jobrunner](queue_job_cron_jobrunner/) | 18.0.1.0.1 | ivantodorovich | Run jobs without a dedicated JobRunner [queue_job_subscribe](queue_job_subscribe/) | 18.0.1.0.0 | | Control which users are subscribed to queue job notifications [test_queue_job](test_queue_job/) | 18.0.1.0.2 | | Queue Job Tests [test_queue_job_batch](test_queue_job_batch/) | 18.0.1.0.0 | | Test Job Queue Batch diff --git a/queue_job_cron_jobrunner/README.rst b/queue_job_cron_jobrunner/README.rst index 64555223a3..8615285dec 100644 --- a/queue_job_cron_jobrunner/README.rst +++ b/queue_job_cron_jobrunner/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + ======================== Queue Job Cron Jobrunner ======================== @@ -7,13 +11,13 @@ Queue Job Cron Jobrunner !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:8805630c706cd2c715ed4e9086e130d580daff40f87890af0f3a2c928c01db16 + !! source digest: sha256:3c8052bb9647ac1c2222b7bbe43133884ab314534ef09686a3aef58e6b38f712 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png :target: https://odoo-community.org/page/development-status :alt: Alpha -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png :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 diff --git a/queue_job_cron_jobrunner/__manifest__.py b/queue_job_cron_jobrunner/__manifest__.py index ff54857efd..ca5d211a4f 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.0", + "version": "18.0.1.0.1", "development_status": "Alpha", "author": "Camptocamp SA, Odoo Community Association (OCA)", "maintainers": ["ivantodorovich"], diff --git a/queue_job_cron_jobrunner/static/description/index.html b/queue_job_cron_jobrunner/static/description/index.html index eb4aba0576..9efaba8690 100644 --- a/queue_job_cron_jobrunner/static/description/index.html +++ b/queue_job_cron_jobrunner/static/description/index.html @@ -3,7 +3,7 @@ -Queue Job Cron Jobrunner +README.rst -
-

Queue Job Cron Jobrunner

+
+ + +Odoo Community Association + +
+

Queue Job Cron Jobrunner

-

Alpha License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

+

Alpha License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

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 @@ -406,7 +411,7 @@

Queue Job Cron Jobrunner

-

Configuration

+

Configuration

Warning

Don’t use this module if you’re already running the regular queue_job runner.

@@ -428,7 +433,7 @@

Configuration

-

Known issues / Roadmap

+

Known issues / Roadmap

  • Support channel capacity and priority. (See _acquire_one_job)
  • Gracefully handle CronWorker CPU timeouts. (See _job_runner)
  • @@ -437,7 +442,7 @@

    Known issues / Roadmap

-

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 @@ -445,15 +450,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Camptocamp SA
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -480,5 +485,6 @@

Maintainers

+