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.
4 changes: 2 additions & 2 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 @@ -27,7 +27,7 @@
"/queue_job/static/src/views/**/*",
],
},
"installable": False,
"installable": True,
"development_status": "Mature",
"maintainers": ["guewen"],
"post_init_hook": "post_init_hook",
Expand Down
2 changes: 1 addition & 1 deletion queue_job/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _create_graph_test_jobs(
priority=priority,
max_retries=max_retries,
channel=channel,
description="%s #%d" % (description, current_count),
description=f"{description} #{current_count}",
)._test_job(failure_rate=failure_rate)
)

Expand Down
3 changes: 2 additions & 1 deletion queue_job/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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


class JobSerialized(fields.Json):
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
7 changes: 3 additions & 4 deletions queue_job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def perform(self):
# traceback and message:
# http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/
new_exc = FailedJobError(
"Max. retries (%d) reached: %s" % (self.max_retries, value or type_)
f"Max. retries ({self.max_retries}) reached: {value or type_}"
)
raise new_exc from err
raise
Expand Down Expand Up @@ -813,7 +813,7 @@ def set_failed(self, **kw):
setattr(self, k, v)

def __repr__(self):
return "<Job %s, priority:%d>" % (self.uuid, self.priority)
return f"<Job {self.uuid}, priority:{self.priority}>"

def _get_retry_seconds(self, seconds=None):
retry_pattern = self.job_config.retry_pattern
Expand Down Expand Up @@ -856,8 +856,7 @@ def related_action(self):
funcname = record._default_related_action
if not isinstance(funcname, str):
raise ValueError(
"related_action must be the name of the "
"method on queue.job as string"
"related_action must be the name of the method on queue.job as string"
)
action = getattr(record, funcname)
action_kwargs = self.job_config.related_action_kwargs
Expand Down
3 changes: 2 additions & 1 deletion queue_job/jobrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
else:
queue_job_config = {}
except ImportError:
queue_job_config = config.misc.get("queue_job", {})
# queue_job_config = config.misc.get("queue_job", {})
queue_job_config = {} # misc removed from config on Oct 9, 2024


from .runner import QueueJobRunner, _channels
Expand Down
12 changes: 4 additions & 8 deletions queue_job/jobrunner/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,9 @@ def get_subchannel_by_name(self, subchannel_name):

def __str__(self):
capacity = "∞" if self.capacity is None else str(self.capacity)
return "%s(C:%s,Q:%d,R:%d,F:%d)" % (
self.fullname,
capacity,
len(self._queue),
len(self._running),
len(self._failed),
return (
f"{self.fullname}(C:{capacity},"
f"Q:{self._queue},R:{self._running},F:{self._failed})"
)

def remove(self, job):
Expand Down Expand Up @@ -894,8 +891,7 @@ def parse_simple_config(cls, config_string):
)
if k in config:
raise ValueError(
f"Invalid channel config {config_string}: "
f"duplicate key {k}"
f"Invalid channel config {config_string}: duplicate key {k}"
)
config[k] = v
else:
Expand Down
12 changes: 8 additions & 4 deletions queue_job/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,15 @@ def _job_prepare_context_before_enqueue(self):
if key in self._job_prepare_context_before_enqueue_keys()
}

# Odoo have deprecated _patch_method and api.propagate in v16
@classmethod
def _patch_method(cls, name, method):
origin = getattr(cls, name)
method.origin = origin
# propagate decorators from origin to method, and apply api decorator
wrapped = api.propagate(origin, method)
wrapped.origin = origin
setattr(cls, name, wrapped)

# propagate appeared to only deal with the returns decorator
# which is now, also, deprecated
# wrapped = api.propagate(origin, method)
# wrapped.origin = origin
# setattr(cls, name, wrapped)
setattr(cls, name, method)
31 changes: 12 additions & 19 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.addons.base_sparse_field.models.fields import Serialized

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

def init(self):
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):
# Used by Job.job_record_with_same_identity_key
self._cr.execute(
self.env.cr.execute(
"SELECT indexname FROM pg_indexes WHERE indexname = %s ",
("queue_job_identity_key_state_partial_index",),
)
if not self.env.cr.fetchone():
self.env.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;"
)
if not index_exists(self._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);"
)

@api.depends("dependencies")
def _compute_dependency_graph(self):
jobs_groups = self.env["queue.job"].read_group(
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"],
["id:array_agg"],
)
ids_per_graph_uuid = {
group["graph_uuid"]: group["ids"] for group in jobs_groups
}
ids_per_graph_uuid = {group[0]: group[1] for group in jobs_groups}
for record in self:
if not record.graph_uuid:
record.dependency_graph = {}
Expand Down Expand Up @@ -216,7 +209,7 @@ def _dependency_graph_vis_node(self):
}

def _compute_graph_jobs_count(self):
jobs_groups = self.env["queue.job"].read_group(
jobs_groups = self.env["queue.job"]._read_group(
[
(
"graph_uuid",
Expand Down Expand Up @@ -356,7 +349,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
7 changes: 4 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,10 @@ 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")
]
_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
3 changes: 1 addition & 2 deletions queue_job/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
</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"
name="user_ids"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
</record>
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
5 changes: 2 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 @@ -212,7 +211,7 @@ def assert_enqueued_job(self, method, args=None, kwargs=None, properties=None):

if expected_call not in actual_calls:
raise AssertionError(
"Job {} was not enqueued.\n" "Actual enqueued jobs:\n{}".format(
"Job {} was not enqueued.\nActual enqueued jobs:\n{}".format(
self._format_job_call(expected_call),
"\n".join(
f" * {self._format_job_call(call)}" for call in actual_calls
Expand Down Expand Up @@ -414,7 +413,7 @@ 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
Expand Down
Loading
Loading