Skip to content
Closed
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
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_import_async/|
^queue_job/|
^queue_job_batch/|
^queue_job_cron/|
^queue_job_cron_jobrunner/|
^queue_job_subscribe/|
^test_queue_job/|
^test_queue_job_batch/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
Expand Down
10 changes: 5 additions & 5 deletions queue_job/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Job Queue
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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
:target: https://github.com/OCA/queue/tree/19.0/queue_job
: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
:target: https://translation.odoo-community.org/projects/queue-19-0/queue-19-0-queue_job
: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|
Expand Down Expand Up @@ -661,7 +661,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/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 <https://github.com/OCA/queue/issues/new?body=module:%20queue_job%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -720,6 +720,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-guewen|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 3 additions & 3 deletions queue_job/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "Job Queue",
"version": "18.0.2.0.2",
"version": "19.0.1.0.0",
"author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
"license": "LGPL-3",
Expand All @@ -24,10 +24,10 @@
],
"assets": {
"web.assets_backend": [
"/queue_job/static/src/views/**/*",
"queue_job/static/src/views/**/*",
],
},
"installable": False,
"installable": True,
"development_status": "Mature",
"maintainers": ["guewen"],
"post_init_hook": "post_init_hook",
Expand Down
5 changes: 3 additions & 2 deletions queue_job/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from psycopg2.extras import Json as PsycopgJson

from odoo import fields, models
from odoo.tools.misc import SENTINEL
from odoo.tools.func import lazy


Expand Down Expand Up @@ -38,7 +39,7 @@ class JobSerialized(fields.Json):
),
}

def __init__(self, string=fields.SENTINEL, base_type=fields.SENTINEL, **kwargs):
def __init__(self, string=SENTINEL, base_type=SENTINEL, **kwargs):
super().__init__(string=string, _base_type=base_type, **kwargs)

def _setup_attrs(self, model, name): # pylint: disable=missing-return
Expand Down Expand Up @@ -66,7 +67,7 @@ def convert_to_cache(self, value, record, validate=True):
def convert_to_record(self, value, record):
default = self._base_type_default_json(record.env)
value = value or default
if not isinstance(value, (str | bytes | bytearray)):
if not isinstance(value, (str, bytes, bytearray)):
value = json.dumps(value, cls=JobEncoder)
return json.loads(value, cls=JobDecoder, env=record.env)

Expand Down
2 changes: 1 addition & 1 deletion queue_job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def _get_retry_seconds(self, seconds=None):
break
elif not seconds:
seconds = RETRY_INTERVAL
if isinstance(seconds, (list | tuple)):
if isinstance(seconds, (list, tuple)):
seconds = randint(seconds[0], seconds[1])
return seconds

Expand Down
31 changes: 30 additions & 1 deletion queue_job/jobrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,43 @@
from odoo.tools import config

try:
# Preferred source when available: structured [queue_job] section provided
# by OCA's server_environment addon.
from odoo.addons.server_environment import serv_config

if serv_config.has_section("queue_job"):
queue_job_config = serv_config["queue_job"]
else:
queue_job_config = {}
except ImportError:
queue_job_config = config.misc.get("queue_job", {})
# Odoo 19: config.misc is no longer available. Build a minimal config
# from flat odoo.conf options so the runner works without server_environment.
queue_job_config = {}

# Merge flat odoo.conf options as a fallback (applies regardless of whether
# server_environment is installed). Precedence is enforced later where used:
# - Environment variables (highest) are read directly in runner functions
# - Then values coming from server_environment's [queue_job] section (above)
# - Finally flat odoo.conf options below (lowest)
#
# Supported flat options (under the [options] section in odoo.conf):
# queue_job_channels = root:2,mychan:1
# queue_job_jobrunner_db_host = localhost
# queue_job_jobrunner_db_port = 5432
# queue_job_jobrunner_db_user = odoo_queue
# queue_job_jobrunner_db_password = odoo_queue
_flat = {}
channels = config.get("queue_job_channels")
if channels:
_flat["channels"] = channels
for p in ("host", "port", "user", "password"):
v = config.get(f"queue_job_jobrunner_db_{p}")
if v:
_flat[f"jobrunner_db_{p}"] = v

# Do not override keys coming from server_environment if present
for k, v in _flat.items():
queue_job_config.setdefault(k, v)


from .runner import QueueJobRunner, _channels
Expand Down
21 changes: 19 additions & 2 deletions queue_job/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,26 @@ def _job_prepare_context_before_enqueue(self):

@classmethod
def _patch_method(cls, name, method):
"""Patch ``name`` with ``method`` preserving API metadata (Odoo 19).

Odoo 19 no longer exposes ``api.propagate``. We emulate the
propagation by using ``functools.update_wrapper`` and copying the
decorator metadata which Odoo relies on (see orm.decorators).
"""
origin = getattr(cls, name)
method.origin = origin
# propagate decorators from origin to method, and apply api decorator
wrapped = api.propagate(origin, method)
# carry over wrapper attributes (name, doc, etc.)
wrapped = functools.update_wrapper(method, origin)
# propagate common decorator metadata used by the framework
for attr in (
"_constrains",
"_depends",
"_onchange",
"_ondelete",
"_api_model",
"_api_private",
):
if hasattr(origin, attr):
setattr(wrapped, attr, getattr(origin, attr))
wrapped.origin = origin
setattr(cls, name, wrapped)
57 changes: 32 additions & 25 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from datetime import datetime, timedelta

from odoo import _, api, exceptions, fields, models
from odoo.tools import config, html_escape, index_exists
from odoo.tools import config, html_escape
from odoo.tools.sql import create_index, index_exists

from odoo.addons.base_sparse_field.models.fields import Serialized

Expand Down Expand Up @@ -127,38 +128,44 @@ class QueueJob(models.Model):
worker_pid = fields.Integer(readonly=True)

def init(self):
# Odoo 19: self._cr deprecated, use self.env.cr; prefer tools.sql helpers for idempotent DDL
cr = self.env.cr
index_1 = "queue_job_identity_key_state_partial_index"
index_2 = "queue_job_channel_date_done_date_created_index"
if not index_exists(self._cr, index_1):
if not index_exists(cr, index_1):
# Used by Job.job_record_with_same_identity_key
self._cr.execute(
"CREATE INDEX queue_job_identity_key_state_partial_index "
"ON queue_job (identity_key) WHERE state in ('pending', "
"'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;"
create_index(
cr,
index_1,
"queue_job",
["identity_key"],
where="state in ('pending','enqueued','wait_dependencies') AND identity_key IS NOT NULL",
comment="Queue Job: partial index for identity_key on active states",
)
if not index_exists(self._cr, index_2):
if not index_exists(cr, index_2):
# Used by <queue.job>.autovacuum
self._cr.execute(
"CREATE INDEX queue_job_channel_date_done_date_created_index "
"ON queue_job (channel, date_done, date_created);"
create_index(
cr,
index_2,
"queue_job",
["channel", "date_done", "date_created"],
comment="Queue Job: index to accelerate autovacuum",
)

@api.depends("dependencies")
def _compute_dependency_graph(self):
jobs_groups = self.env["queue.job"].read_group(
[
(
"graph_uuid",
"in",
[uuid for uuid in self.mapped("graph_uuid") if uuid],
)
],
["graph_uuid", "ids:array_agg(id)"],
["graph_uuid"],
)
ids_per_graph_uuid = {
group["graph_uuid"]: group["ids"] for group in jobs_groups
}
uuids = [uuid for uuid in self.mapped("graph_uuid") if uuid]
ids_per_graph_uuid = {}
if uuids:
# Odoo 19: avoid ORM warning by using _read_group with 'id:recordset' aggregate
rows = self.env["queue.job"]._read_group(
[("graph_uuid", "in", uuids)],
groupby=["graph_uuid"],
aggregates=["id:recordset"],
)
# rows -> list of tuples: (graph_uuid, recordset)
for graph_uuid, recs in rows:
ids_per_graph_uuid[graph_uuid] = recs.ids
for record in self:
if not record.graph_uuid:
record.dependency_graph = {}
Expand Down Expand Up @@ -356,7 +363,7 @@ def _subscribe_users_domain(self):
if not group:
return None
companies = self.mapped("company_id")
domain = [("groups_id", "=", group.id)]
domain = [("group_ids", "=", group.id)]
if companies:
domain.append(("company_id", "in", companies.ids))
return domain
Expand Down
8 changes: 5 additions & 3 deletions queue_job/models/queue_job_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class QueueJobChannel(models.Model):
default=lambda self: self.env["queue.job"]._removal_interval, required=True
)

_sql_constraints = [
("name_uniq", "unique(complete_name)", "Channel complete name must be unique")
]
# Odoo 19: _sql_constraints removed. Use models.Constraint instead.
_name_uniq = models.Constraint(
"UNIQUE(complete_name)",
"Channel complete name must be unique",
)

@api.depends("name", "parent_id.complete_name")
def _compute_complete_name(self):
Expand Down
2 changes: 1 addition & 1 deletion queue_job/models/queue_job_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _check_retry_pattern(self):
) from ex

def _retry_value_type_check(self, value):
if isinstance(value, (tuple | list)):
if isinstance(value, (tuple, list)):
if len(value) != 2:
raise ValueError
[self._retry_value_type_check(element) for element in value]
Expand Down
14 changes: 9 additions & 5 deletions queue_job/security/security.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<!-- New: Odoo 19 groups are classified by res.groups.privilege -->
<record model="res.groups.privilege" id="privilege_queue_job">
<field name="name">Job Queue</field>
<field name="sequence">20</field>
</record>
<record model="ir.module.category" id="module_category_queue_job">
<field name="name">Job Queue</field>
<field name="sequence">20</field>
</record>
<record id="group_queue_job_manager" model="res.groups">
<field name="name">Job Queue Manager</field>
<field name="category_id" ref="module_category_queue_job" />
<field
name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
<!-- Odoo 19: use privilege_id instead of deprecated category_id -->
<field name="privilege_id" ref="privilege_queue_job" />
<!-- Odoo 19: res.groups uses user_ids M2M and Command API -->
<field name="user_ids" eval="[Command.link(ref('base.user_root')), Command.link(ref('base.user_admin'))]"/>
</record>
</data>
<data noupdate="1">
Expand Down
6 changes: 3 additions & 3 deletions queue_job/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ <h1>Job Queue</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:58f9182440bb316576671959b69148ea5454958f9ae8db75bccd30c89012676d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/18.0/queue_job"><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"><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>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/19.0/queue_job"><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"><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>
<p>This addon adds an integrated Job Queue to Odoo.</p>
<p>It allows to postpone method calls executed asynchronously.</p>
<p>Jobs are executed in the background by a <tt class="docutils literal">Jobrunner</tt>, in their own
Expand Down Expand Up @@ -962,7 +962,7 @@ <h2><a class="toc-backref" href="#toc-entry-14">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%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20queue_job%0Aversion:%2019.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">
Expand Down Expand Up @@ -1010,7 +1010,7 @@ <h3><a class="toc-backref" href="#toc-entry-19">Maintainers</a></h3>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/guewen"><img alt="guewen" src="https://github.com/guewen.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/18.0/queue_job">OCA/queue</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/19.0/queue_job">OCA/queue</a> project on GitHub.</p>
<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>
</div>
</div>
Expand Down
11 changes: 8 additions & 3 deletions queue_job/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from unittest import TestCase, mock

from odoo.tests.case import TestCase as _TestCase
from odoo.tests.common import MetaCase

from odoo.addons.queue_job.delay import Graph

Expand Down Expand Up @@ -414,15 +413,21 @@ def test_export(self):
yield delayable_cls, delayable


class OdooDocTestCase(doctest.DocTestCase, _TestCase, MetaCase("DummyCase", (), {})):
class OdooDocTestCase(doctest.DocTestCase, _TestCase):
"""
We need a custom DocTestCase class in order to:
- define test_tags to run as part of standard tests
- output a more meaningful test name than default "DocTestCase.runTest"
"""

def __init__(
self, doctest, optionflags=0, setUp=None, tearDown=None, checker=None, seq=0
self,
doctest,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE,
setUp=None,
tearDown=None,
checker=None,
seq=0,
):
super().__init__(
doctest._dt_test,
Expand Down
Loading
Loading