Skip to content
Merged
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[base_import_async](base_import_async/) | 18.0.1.0.0 | | Import CSV files in the background
[queue_job](queue_job/) | 18.0.1.5.0 | <a href='https://github.com/guewen'><img src='https://github.com/guewen.png' width='32' height='32' style='border-radius:50%;' alt='guewen'/></a> | Job Queue
[queue_job](queue_job/) | 18.0.1.5.2 | <a href='https://github.com/guewen'><img src='https://github.com/guewen.png' width='32' height='32' style='border-radius:50%;' alt='guewen'/></a> | Job Queue
[queue_job_batch](queue_job_batch/) | 18.0.1.0.0 | | Job Queue Batch
[queue_job_cron](queue_job_cron/) | 18.0.1.1.1 | | Scheduled Actions as Queue Jobs
[queue_job_cron_jobrunner](queue_job_cron_jobrunner/) | 18.0.1.0.0 | <a href='https://github.com/ivantodorovich'><img src='https://github.com/ivantodorovich.png' width='32' height='32' style='border-radius:50%;' alt='ivantodorovich'/></a> | Run jobs without a dedicated JobRunner
Expand Down
2 changes: 1 addition & 1 deletion queue_job/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Job Queue
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:52a1fdc25fb3cff5edd8b3dab2375cc6508ef48fa70ee04d6f80b953611a1072
!! source digest: sha256:9ac8c508d24a645a009daaa54689fc301145037c8bc14dc3e3464d2faf16dfb2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
Expand Down
2 changes: 1 addition & 1 deletion 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.1.5.0",
"version": "18.0.1.5.2",
"author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
"license": "LGPL-3",
Expand Down
64 changes: 38 additions & 26 deletions queue_job/jobrunner/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2015-2016 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
import logging
from collections import namedtuple
from functools import total_ordering
from heapq import heappop, heappush
from weakref import WeakValueDictionary
Expand All @@ -10,6 +11,7 @@
from ..job import CANCELLED, DONE, ENQUEUED, FAILED, PENDING, STARTED, WAIT_DEPENDENCIES

NOT_DONE = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED, FAILED)
JobSortingKey = namedtuple("SortingKey", "eta priority date_created seq")

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -108,7 +110,7 @@ class ChannelJob:
job that are necessary to prioritise them.

Channel jobs are comparable according to the following rules:
* jobs with an eta come before all other jobs
* jobs with an eta cannot be compared with jobs without
* then jobs with a smaller eta come first
* then jobs with a smaller priority come first
* then jobs with a smaller creation time come first
Expand All @@ -135,14 +137,18 @@ class ChannelJob:
>>> j3 < j1
True

j4 and j5 comes even before j3, because they have an eta
j4 and j5 have an eta, they cannot be compared with j3

>>> j4 = ChannelJob(None, None, 4,
... seq=0, date_created=4, priority=9, eta=9)
>>> j5 = ChannelJob(None, None, 5,
... seq=0, date_created=5, priority=9, eta=9)
>>> j4 < j5 < j3
>>> j4 < j5
True
>>> j4 < j3
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'int' and 'NoneType'

j6 has same date_created and priority as j5 but a smaller eta

Expand All @@ -153,7 +159,7 @@ class ChannelJob:

Here is the complete suite:

>>> j6 < j4 < j5 < j3 < j1 < j2
>>> j6 < j4 < j5 and j3 < j1 < j2
True

j0 has the same properties as j1 but they are not considered
Expand All @@ -173,25 +179,13 @@ class ChannelJob:

"""

__slots__ = (
"db_name",
"channel",
"uuid",
"seq",
"date_created",
"priority",
"eta",
"__weakref__",
)
__slots__ = ("db_name", "channel", "uuid", "_sorting_key", "__weakref__")

def __init__(self, db_name, channel, uuid, seq, date_created, priority, eta):
self.db_name = db_name
self.channel = channel
self.uuid = uuid
self.seq = seq
self.date_created = date_created
self.priority = priority
self.eta = eta
self._sorting_key = JobSortingKey(eta, priority, date_created, seq)

def __repr__(self):
return f"<ChannelJob {self.uuid}>"
Expand All @@ -202,18 +196,36 @@ def __eq__(self, other):
def __hash__(self):
return id(self)

def set_no_eta(self):
self._sorting_key = JobSortingKey(None, *self._sorting_key[1:])

@property
def seq(self):
return self._sorting_key.seq

@property
def date_created(self):
return self._sorting_key.date_created

@property
def priority(self):
return self._sorting_key.priority

@property
def eta(self):
return self._sorting_key.eta

def sorting_key(self):
return self.eta, self.priority, self.date_created, self.seq
# DEPRECATED
return self._sorting_key

def sorting_key_ignoring_eta(self):
return self.priority, self.date_created, self.seq
return self._sorting_key[1:]

def __lt__(self, other):
if self.eta and not other.eta:
return True
elif not self.eta and other.eta:
return False
return self.sorting_key() < other.sorting_key()
# Do not compare job where ETA is set with job where it is not
# If one job 'eta' is set, and the other is None, it raises TypeError
return self._sorting_key < other._sorting_key


class ChannelQueue:
Expand Down Expand Up @@ -323,7 +335,7 @@ def remove(self, job):
def pop(self, now):
while self._eta_queue and self._eta_queue[0].eta <= now:
eta_job = self._eta_queue.pop()
eta_job.eta = None
eta_job.set_no_eta()
self._queue.add(eta_job)
if self.sequential and self._eta_queue and self._queue:
eta_job = self._eta_queue[0]
Expand Down
Binary file modified queue_job/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 77 additions & 1 deletion queue_job/static/description/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion queue_job/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h1>Job Queue</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:52a1fdc25fb3cff5edd8b3dab2375cc6508ef48fa70ee04d6f80b953611a1072
!! source digest: sha256:9ac8c508d24a645a009daaa54689fc301145037c8bc14dc3e3464d2faf16dfb2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>This addon adds an integrated Job Queue to Odoo.</p>
Expand Down