Skip to content

Commit 1b17ecf

Browse files
committed
[IMP] queue_job: use queue_job_lock model
A model is better than a manually managed table as it will protect the table from deletion by database_cleanup.
1 parent b94241b commit 1b17ecf

File tree

7 files changed

+28
-35
lines changed

7 files changed

+28
-35
lines changed

queue_job/job.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ def add_lock_record(self):
230230
self.env.cr.execute(
231231
"""
232232
INSERT INTO
233-
queue_job_locks (id)
233+
queue_job_lock (id, queue_job_id)
234234
SELECT
235-
id
235+
id, id
236236
FROM
237237
queue_job
238238
WHERE
@@ -256,9 +256,9 @@ def lock(self):
256256
SELECT
257257
*
258258
FROM
259-
queue_job_locks
259+
queue_job_lock
260260
WHERE
261-
id in (
261+
queue_job_id in (
262262
SELECT
263263
id
264264
FROM

queue_job/jobrunner/runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ def _query_requeue_dead_jobs(self):
344344
WHERE
345345
id in (
346346
SELECT
347-
id
347+
queue_job_id
348348
FROM
349-
queue_job_locks
349+
queue_job_lock
350350
WHERE
351-
id in (
351+
queue_job_id in (
352352
SELECT
353353
id
354354
FROM

queue_job/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from . import queue_job
44
from . import queue_job_channel
55
from . import queue_job_function
6-
from . import queue_job_locks
6+
from . import queue_job_lock

queue_job/models/queue_job_lock.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 ACSONE SA/NV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class QueueJobLock(models.Model):
8+
_name = "queue.job.lock"
9+
_description = "Queue Job Lock"
10+
11+
queue_job_id = fields.Many2one(
12+
comodel_name="queue.job",
13+
required=True,
14+
ondelete="cascade",
15+
index=True,
16+
)

queue_job/models/queue_job_locks.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

queue_job/security/ir.model.access.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
22
access_queue_job_manager,queue job manager,queue_job.model_queue_job,queue_job.group_queue_job_manager,1,1,1,1
3+
access_queue_job_lock_manager,queue job lock manager,queue_job.model_queue_job_lock,queue_job.group_queue_job_manager,1,0,0,0
34
access_queue_job_function_manager,queue job functions manager,queue_job.model_queue_job_function,queue_job.group_queue_job_manager,1,1,1,1
45
access_queue_job_channel_manager,queue job channel manager,queue_job.model_queue_job_channel,queue_job.group_queue_job_manager,1,1,1,1
56
access_queue_requeue_job,queue requeue job manager,queue_job.model_queue_requeue_job,queue_job.group_queue_job_manager,1,1,1,1

queue_job/tests/test_requeue_dead_job.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def get_locks(self, uuid, cr=None):
4040
cr.execute(
4141
"""
4242
SELECT
43-
id
43+
queue_job_id
4444
FROM
45-
queue_job_locks
45+
queue_job_lock
4646
WHERE
47-
id IN (
47+
queue_job_id IN (
4848
SELECT
4949
id
5050
FROM

0 commit comments

Comments
 (0)