Skip to content
Open
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_import_async/|
^queue_job/|
^queue_job_batch/|
^queue_job_cron/|
^queue_job_cron_jobrunner/|
Expand Down
13 changes: 6 additions & 7 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 @@ -696,8 +696,7 @@ Contributors
Other credits
-------------

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.


Maintainers
-----------
Expand All @@ -720,6 +719,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
3 changes: 2 additions & 1 deletion queue_job/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from psycopg2 import OperationalError, errorcodes
from werkzeug.exceptions import BadRequest, Forbidden

from odoo import SUPERUSER_ID, _, api, http
from odoo import _, api, http
from odoo.api import SUPERUSER_ID
from odoo.modules.registry import Registry
from odoo.service.model import PG_CONCURRENCY_ERRORS_TO_RETRY

Expand Down
22 changes: 9 additions & 13 deletions queue_job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from random import randint

import odoo
from odoo.fields import Domain

from .exception import FailedJobError, NoSuchJobError, RetryableJobError

Expand Down Expand Up @@ -337,23 +338,19 @@ def _load_from_db_record(cls, job_db_record):

def job_record_with_same_identity_key(self):
"""Check if a job to be executed with the same key exists."""
existing = (
self.env["queue.job"]
.sudo()
.search(
[
("identity_key", "=", self.identity_key),
("state", "in", [WAIT_DEPENDENCIES, PENDING, ENQUEUED]),
],
limit=1,
)
domain = Domain.AND(
[
Domain("identity_key", "=", self.identity_key),
Domain("state", "in", [WAIT_DEPENDENCIES, PENDING, ENQUEUED]),
]
)
existing = self.env["queue.job"].sudo().search(domain, limit=1)
return existing

@staticmethod
def db_records_from_uuids(env, job_uuids):
model = env["queue.job"].sudo()
record = model.search([("uuid", "in", tuple(job_uuids))])
record = model.search(Domain("uuid", "in", tuple(job_uuids)))
return record.with_env(env).sudo()

def __init__(
Expand Down Expand Up @@ -856,8 +853,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: 1 addition & 2 deletions queue_job/jobrunner/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,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
29 changes: 0 additions & 29 deletions queue_job/migrations/18.0.1.0.0/pre-migrate.py

This file was deleted.

11 changes: 0 additions & 11 deletions queue_job/migrations/18.0.1.7.0/pre-migration.py

This file was deleted.

66 changes: 26 additions & 40 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime, timedelta

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

from odoo.addons.base_sparse_field.models.fields import Serialized
Expand Down Expand Up @@ -145,20 +146,13 @@ def init(self):

@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"],
graph_uuids = [uuid for uuid in self.mapped("graph_uuid") if uuid]
jobs_groups = self.env["queue.job"]._read_group(
Domain("graph_uuid", "in", graph_uuids),
groupby=["graph_uuid"],
aggregates=["id:array_agg"],
)
ids_per_graph_uuid = {
group["graph_uuid"]: group["ids"] for group in jobs_groups
}
ids_per_graph_uuid = {graph_uuid: ids for graph_uuid, ids in jobs_groups}
for record in self:
if not record.graph_uuid:
record.dependency_graph = {}
Expand Down Expand Up @@ -216,20 +210,13 @@ def _dependency_graph_vis_node(self):
}

def _compute_graph_jobs_count(self):
jobs_groups = self.env["queue.job"].read_group(
[
(
"graph_uuid",
"in",
[uuid for uuid in self.mapped("graph_uuid") if uuid],
)
],
["graph_uuid"],
["graph_uuid"],
graph_uuids = [uuid for uuid in self.mapped("graph_uuid") if uuid]
jobs_groups = self.env["queue.job"]._read_group(
Domain("graph_uuid", "in", graph_uuids),
groupby=["graph_uuid"],
aggregates=["__count"],
)
count_per_graph_uuid = {
group["graph_uuid"]: group["graph_uuid_count"] for group in jobs_groups
}
count_per_graph_uuid = {graph_uuid: count for graph_uuid, count in jobs_groups}
for record in self:
record.graph_jobs_count = count_per_graph_uuid.get(record.graph_uuid) or 0

Expand Down Expand Up @@ -285,7 +272,7 @@ def open_related_action(self):
def open_graph_jobs(self):
"""Return action that opens all jobs of the same graph"""
self.ensure_one()
jobs = self.env["queue.job"].search([("graph_uuid", "=", self.graph_uuid)])
jobs = self.env["queue.job"].search(Domain("graph_uuid", "=", self.graph_uuid))

action = self.env["ir.actions.act_window"]._for_xml_id(
"queue_job.action_queue_job"
Expand All @@ -294,7 +281,7 @@ def open_graph_jobs(self):
{
"name": _("Jobs for graph %s") % (self.graph_uuid),
"context": {},
"domain": [("id", "in", jobs.ids)],
"domain": Domain("id", "in", jobs.ids),
}
)
return action
Expand Down Expand Up @@ -354,11 +341,11 @@ def _subscribe_users_domain(self):
"""Subscribe all users having the 'Queue Job Manager' group"""
group = self.env.ref("queue_job.group_queue_job_manager")
if not group:
return None
return Domain([])
companies = self.mapped("company_id")
domain = [("groups_id", "=", group.id)]
domain = Domain("groups_id", "=", group.id)
if companies:
domain.append(("company_id", "in", companies.ids))
domain &= Domain("company_id", "in", companies.ids)
return domain

def _message_failed_job(self):
Expand All @@ -380,24 +367,23 @@ def _needaction_domain_get(self):

:return: domain or False is no action
"""
return [("state", "=", "failed")]
return Domain("state", "=", "failed")

def autovacuum(self):
"""Delete all jobs done based on the removal interval defined on the
channel

Called from a cron.
"""
for channel in self.env["queue.job.channel"].search([]):
for channel in self.env["queue.job.channel"].search(Domain([])):
deadline = datetime.now() - timedelta(days=int(channel.removal_interval))
while True:
domain = Domain.OR(
Domain("date_done", "<=", deadline),
Domain("date_cancelled", "<=", deadline),
) & Domain("channel", "=", channel.complete_name)
jobs = self.search(
[
"|",
("date_done", "<=", deadline),
("date_cancelled", "<=", deadline),
("channel", "=", channel.complete_name),
],
domain,
order="date_done, date_created",
limit=1000,
)
Expand Down Expand Up @@ -437,7 +423,7 @@ def related_action_open_record(self):
{
"name": _("Related Records"),
"view_mode": "list,form",
"domain": [("id", "in", records.ids)],
"domain": Domain("id", "in", records.ids),
}
)
return action
Expand Down
8 changes: 7 additions & 1 deletion queue_job/models/queue_job_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


from odoo import _, api, exceptions, fields, models
from odoo.fields import Domain


class QueueJobChannel(models.Model):
Expand Down Expand Up @@ -60,7 +61,12 @@ def create(self, vals_list):
parent_id = vals.get("parent_id")
if name and parent_id:
existing = self.search(
[("name", "=", name), ("parent_id", "=", parent_id)]
Domain.AND(
[
Domain("name", "=", name),
Domain("parent_id", "=", parent_id),
]
)
)
if existing:
if not existing.get_metadata()[0].get("noupdate"):
Expand Down
9 changes: 6 additions & 3 deletions queue_job/models/queue_job_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import namedtuple

from odoo import _, api, exceptions, fields, models, tools
from odoo.fields import Domain

from ..fields import JobSerialized

Expand Down Expand Up @@ -95,7 +96,9 @@ def _inverse_name(self):
model_name = groups[1]
method = groups[2]
model = (
self.env["ir.model"].sudo().search([("model", "=", model_name)], limit=1)
self.env["ir.model"]
.sudo()
.search(Domain("model", "=", model_name), limit=1)
)
if not model:
raise exceptions.UserError(_("Model {} not found").format(model_name))
Expand Down Expand Up @@ -173,7 +176,7 @@ def _parse_retry_pattern(self):

@tools.ormcache("name")
def job_config(self, name):
config = self.search([("name", "=", name)], limit=1)
config = self.search(Domain("name", "=", name), limit=1)
if not config:
return self.job_default_config()
retry_pattern = config._parse_retry_pattern()
Expand Down Expand Up @@ -250,7 +253,7 @@ def create(self, vals_list):
for vals in vals_list:
name = vals.get("name")
if name:
existing = self.search([("name", "=", name)], limit=1)
existing = self.search(Domain("name", "=", name), limit=1)
if existing:
if not existing.get_metadata()[0].get("noupdate"):
existing.write(vals)
Expand Down
1 change: 0 additions & 1 deletion queue_job/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
Loading