Skip to content

Commit 4e12088

Browse files
committed
[19.0][MIG] queue_job_cron: migrate
- Migrate queue_job_cron and queue_job_cron_jobrunner to 19.0\n- Update tests and pre-commit exclusions
1 parent d2a8e90 commit 4e12088

File tree

9 files changed

+113
-71
lines changed

9 files changed

+113
-71
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ exclude: |
33
# NOT INSTALLABLE ADDONS
44
^base_import_async/|
55
^queue_job_batch/|
6-
^queue_job_cron/|
7-
^queue_job_cron_jobrunner/|
86
^queue_job_subscribe/|
97
^test_queue_job_batch/|
108
# END NOT INSTALLABLE ADDONS

queue_job_cron/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Scheduled Actions as Queue Jobs
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
24-
:target: https://github.com/OCA/queue/tree/18.0/queue_job_cron
24+
:target: https://github.com/OCA/queue/tree/19.0/queue_job_cron
2525
:alt: OCA/queue
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_cron
27+
:target: https://translation.odoo-community.org/projects/queue-19-0/queue-19-0-queue_job_cron
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -89,7 +89,7 @@ Bug Tracker
8989
Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/issues>`_.
9090
In case of trouble, please check there if your issue has already been reported.
9191
If you spotted it first, help us to smash it by providing a detailed and welcomed
92-
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
92+
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
9393

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

@@ -128,6 +128,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
128128
mission is to support the collaborative development of Odoo features and
129129
promote its widespread use.
130130

131-
This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/18.0/queue_job_cron>`_ project on GitHub.
131+
This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/19.0/queue_job_cron>`_ project on GitHub.
132132

133133
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

queue_job_cron/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
{
55
"name": "Scheduled Actions as Queue Jobs",
6-
"version": "18.0.1.1.1",
6+
"version": "19.0.1.0.0",
77
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/queue",
99
"license": "AGPL-3",
1010
"category": "Generic Modules",
1111
"depends": ["queue_job"],
1212
"data": ["data/data.xml", "views/ir_cron_view.xml"],
13-
"installable": False,
13+
"installable": True,
1414
}

queue_job_cron/models/ir_cron.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3-
import logging
4-
53
from odoo import api, fields, models
64

75
from odoo.addons.queue_job.job import identity_exact
86

9-
_logger = logging.getLogger(__name__)
10-
117

128
class IrCron(models.Model):
139
_inherit = "ir.cron"

queue_job_cron/static/description/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Scheduled Actions as Queue Jobs</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:61571266d30481c36fe1d1751209760e580f0fdd528d8a39b9610f37a442c920
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/18.0/queue_job_cron"><img alt="OCA/queue" src="https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_cron"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/queue&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/19.0/queue_job_cron"><img alt="OCA/queue" src="https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/queue-19-0/queue-19-0-queue_job_cron"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/queue&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module extends the functionality of queue_job and allows to run an
379379
Odoo cron as a queue job.</p>
380380
<p><strong>Table of contents</strong></p>
@@ -445,7 +445,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h2>
445445
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/queue/issues">GitHub Issues</a>.
446446
In case of trouble, please check there if your issue has already been reported.
447447
If you spotted it first, help us to smash it by providing a detailed and welcomed
448-
<a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
448+
<a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
449449
<p>Do not contact contributors directly about support or help with technical issues.</p>
450450
</div>
451451
<div class="section" id="credits">
@@ -479,7 +479,7 @@ <h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
479479
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
480480
mission is to support the collaborative development of Odoo features and
481481
promote its widespread use.</p>
482-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/18.0/queue_job_cron">OCA/queue</a> project on GitHub.</p>
482+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/19.0/queue_job_cron">OCA/queue</a> project on GitHub.</p>
483483
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
484484
</div>
485485
</div>
Lines changed: 93 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
34
from odoo.tests.common import TransactionCase
45

56

@@ -8,20 +9,23 @@ def setUp(self):
89
super().setUp()
910

1011
def test_queue_job_cron(self):
11-
QueueJob = self.env["queue.job"]
1212
default_channel = self.env.ref("queue_job_cron.channel_root_ir_cron")
1313
cron = self.env.ref("queue_job.ir_cron_autovacuum_queue_jobs")
1414
self.assertFalse(cron.run_as_queue_job)
1515

16-
cron.method_direct_trigger()
17-
nb_jobs = QueueJob.search_count([("name", "=", cron.name)])
16+
# Use core helper enter_registry_test_mode so method_direct_trigger
17+
# runs safely under 19.0 test harness (avoids cross-cursor
18+
# visibility/locking quirks during tests).
19+
with self.enter_registry_test_mode():
20+
cron.method_direct_trigger()
21+
nb_jobs = self.env["queue.job"].search_count([("name", "=", cron.name)])
1822
self.assertEqual(nb_jobs, 0)
1923

24+
# Enable run_as_queue_job and trigger via method_direct_trigger
2025
cron.write({"run_as_queue_job": True, "channel_id": default_channel.id})
21-
22-
cron.method_direct_trigger()
23-
qjob = QueueJob.search([("name", "=", cron.name)])
24-
26+
with self.enter_registry_test_mode():
27+
cron.method_direct_trigger()
28+
qjob = self.env["queue.job"].search([("name", "=", cron.name)])
2529
self.assertTrue(qjob)
2630
self.assertEqual(qjob.name, cron.name)
2731
self.assertEqual(qjob.priority, cron.priority)
@@ -32,8 +36,13 @@ def test_queue_job_cron_depends(self):
3236
cron = self.env.ref("queue_job.ir_cron_autovacuum_queue_jobs")
3337
default_channel = self.env.ref("queue_job_cron.channel_root_ir_cron")
3438
self.assertFalse(cron.run_as_queue_job)
35-
cron.write({"run_as_queue_job": True})
36-
self.assertEqual(cron.channel_id.id, default_channel.id)
39+
# Write + assert in a fresh cursor to avoid ir.cron row lock
40+
# serialization under 19.0 when scheduler touches it.
41+
with self.registry.cursor() as cr:
42+
env2 = self.env(cr=cr)
43+
cron2 = env2["ir.cron"].browse(cron.id)
44+
cron2.write({"run_as_queue_job": True})
45+
self.assertEqual(cron2.channel_id.id, default_channel.id)
3746

3847
def test_queue_job_cron_run(self):
3948
cron = self.env.ref("queue_job.ir_cron_autovacuum_queue_jobs")
@@ -43,42 +52,81 @@ def test_queue_job_cron_run(self):
4352
def test_queue_job_no_parallelism(self):
4453
cron = self.env.ref("queue_job.ir_cron_autovacuum_queue_jobs")
4554
default_channel = self.env.ref("queue_job_cron.channel_root_ir_cron")
46-
cron.write(
47-
{
48-
"no_parallel_queue_job_run": True,
49-
"run_as_queue_job": True,
50-
"channel_id": default_channel.id,
51-
}
52-
)
53-
cron.method_direct_trigger()
54-
cron.method_direct_trigger()
55-
nb_jobs = self.env["queue.job"].search_count([("name", "=", cron.name)])
56-
self.assertEqual(nb_jobs, 1)
57-
cron.no_parallel_queue_job_run = False
58-
cron.method_direct_trigger()
59-
nb_jobs = self.env["queue.job"].search_count([("name", "=", cron.name)])
60-
self.assertEqual(nb_jobs, 2)
55+
# Configure + enqueue in a fresh cursor to avoid serialization
56+
# conflicts; call _delay_run_job_as_queue_job twice to exercise
57+
# identity-based dedup under no_parallel setting.
58+
with self.registry.cursor() as cr:
59+
env2 = self.env(cr=cr)
60+
cron2 = env2["ir.cron"].browse(cron.id)
61+
cron2.write(
62+
{
63+
"no_parallel_queue_job_run": True,
64+
"run_as_queue_job": True,
65+
"channel_id": default_channel.id,
66+
}
67+
)
68+
# Enqueue twice via the queue path; identity prevents duplicates
69+
cron2._delay_run_job_as_queue_job(server_action=cron2.ir_actions_server_id)
70+
cron2._delay_run_job_as_queue_job(server_action=cron2.ir_actions_server_id)
71+
nb_jobs2 = env2["queue.job"].search_count([("name", "=", cron2.name)])
72+
self.assertEqual(nb_jobs2, 1)
73+
# Allow parallelism and enqueue once more; count increases
74+
cron2.write({"no_parallel_queue_job_run": False})
75+
cron2._delay_run_job_as_queue_job(server_action=cron2.ir_actions_server_id)
76+
nb_jobs2 = env2["queue.job"].search_count([("name", "=", cron2.name)])
77+
self.assertEqual(nb_jobs2, 2)
78+
# Cleanup: enqueues above happen in a committed cursor; remove them to
79+
# avoid leaking pending jobs into subsequent modules (e.g. jobrunner).
80+
with self.registry.cursor() as cr:
81+
env2 = self.env(cr=cr)
82+
env2["queue.job"].sudo().search([("name", "=", cron.name)]).unlink()
6183

6284
def test_queue_job_cron_callback(self):
63-
nb_partners = self.env["res.partner"].search_count([])
64-
nb_jobs = self.env["queue.job"].search_count([])
65-
partner_model = self.env.ref("base.model_res_partner")
66-
action = self.env["ir.actions.server"].create(
67-
{
68-
"name": "Queue job cron callback action create partner",
69-
"state": "code",
70-
"model_id": partner_model.id,
71-
"crud_model_id": partner_model.id,
72-
"code": "model.name_create('job Cron partner')",
73-
}
74-
)
7585
cron = self.env.ref("queue_job.ir_cron_autovacuum_queue_jobs")
76-
cron._callback("Test queue job cron", action.id)
77-
nb_partners_after_cron = self.env["res.partner"].search_count([])
78-
self.assertEqual(nb_partners_after_cron, nb_partners + 1)
79-
cron.write({"run_as_queue_job": True})
80-
cron._callback("Test queue job cron", action.id)
81-
nb_partners_after_cron = self.env["res.partner"].search_count([])
82-
self.assertEqual(nb_partners_after_cron, nb_partners + 1)
83-
nb_jobs_after_cron = self.env["queue.job"].search_count([])
84-
self.assertEqual(nb_jobs_after_cron, nb_jobs + 1)
86+
# Run _callback in a separate cursor because core _callback
87+
# commits/rollbacks; main test cursor forbids it. Assert within the
88+
# same cursor for deterministic visibility.
89+
with self.registry.cursor() as cr:
90+
env2 = self.env(cr=cr)
91+
count_before = env2["res.partner"].search_count([])
92+
partner_model = env2.ref("base.model_res_partner")
93+
action = env2["ir.actions.server"].create(
94+
{
95+
"name": "Queue job cron callback action create partner",
96+
"state": "code",
97+
"model_id": partner_model.id,
98+
"crud_model_id": partner_model.id,
99+
"code": "model.name_create('job Cron partner')",
100+
}
101+
)
102+
env2["ir.cron"].browse(cron.id)._callback("Test queue job cron", action.id)
103+
partners_after = env2["res.partner"].search_count([])
104+
self.assertEqual(partners_after, count_before + 1)
105+
# Phase 2: enable run_as_queue_job and ensure callback enqueues a job
106+
# (not synchronous); use a separate cursor and assert within it.
107+
with self.registry.cursor() as cr:
108+
env2 = self.env(cr=cr)
109+
env2["ir.cron"].browse(cron.id).write({"run_as_queue_job": True})
110+
count_before = env2["res.partner"].search_count([])
111+
jobs_before = env2["queue.job"].search_count([])
112+
partner_model = env2.ref("base.model_res_partner")
113+
action = env2["ir.actions.server"].create(
114+
{
115+
"name": "Queue job cron callback action create partner",
116+
"state": "code",
117+
"model_id": partner_model.id,
118+
"crud_model_id": partner_model.id,
119+
"code": "model.name_create('job Cron partner')",
120+
}
121+
)
122+
env2["ir.cron"].browse(cron.id)._callback("Test queue job cron", action.id)
123+
partners_after = env2["res.partner"].search_count([])
124+
jobs_after = env2["queue.job"].search_count([])
125+
self.assertEqual(partners_after, count_before)
126+
self.assertEqual(jobs_after, jobs_before + 1)
127+
# Cleanup: ensure no leakage across tests when using a shared DB name
128+
with self.registry.cursor() as cr:
129+
env2 = self.env(cr=cr)
130+
cron2 = env2["ir.cron"].browse(cron.id)
131+
jobs = env2["queue.job"].sudo().search([("name", "=", cron2.name)])
132+
jobs.unlink()

queue_job_cron_jobrunner/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Queue Job Cron Jobrunner
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
24-
:target: https://github.com/OCA/queue/tree/18.0/queue_job_cron_jobrunner
24+
:target: https://github.com/OCA/queue/tree/19.0/queue_job_cron_jobrunner
2525
:alt: OCA/queue
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_cron_jobrunner
27+
:target: https://translation.odoo-community.org/projects/queue-19-0/queue-19-0-queue_job_cron_jobrunner
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -102,7 +102,7 @@ Bug Tracker
102102
Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/issues>`_.
103103
In case of trouble, please check there if your issue has already been reported.
104104
If you spotted it first, help us to smash it by providing a detailed and welcomed
105-
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron_jobrunner%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
105+
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_cron_jobrunner%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
106106

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

@@ -142,6 +142,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
142142

143143
|maintainer-ivantodorovich|
144144

145-
This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/18.0/queue_job_cron_jobrunner>`_ project on GitHub.
145+
This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/19.0/queue_job_cron_jobrunner>`_ project on GitHub.
146146

147147
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

queue_job_cron_jobrunner/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Queue Job Cron Jobrunner",
33
"summary": "Run jobs without a dedicated JobRunner",
4-
"version": "18.0.1.0.1",
4+
"version": "19.0.1.0.0",
55
"development_status": "Alpha",
66
"author": "Camptocamp SA, Odoo Community Association (OCA)",
77
"maintainers": ["ivantodorovich"],
@@ -13,5 +13,5 @@
1313
"data/ir_cron.xml",
1414
"views/ir_cron.xml",
1515
],
16-
"installable": False,
16+
"installable": True,
1717
}

0 commit comments

Comments
 (0)