From 0f08b517e85def5dabaa8767b7d25111475086d8 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Mon, 16 Dec 2024 15:47:54 +0100 Subject: [PATCH 1/2] [REF] queue_job: Use set.discard(...) instead of SafeSet --- queue_job/jobrunner/channels.py | 40 +++++++++------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/queue_job/jobrunner/channels.py b/queue_job/jobrunner/channels.py index c06f7b49d8..6812aa4960 100644 --- a/queue_job/jobrunner/channels.py +++ b/queue_job/jobrunner/channels.py @@ -75,8 +75,7 @@ def __contains__(self, o): def add(self, o): if o is None: raise ValueError() - if o in self._removed: - self._removed.remove(o) + self._removed.discard(o) if o in self._known: return self._known.add(o) @@ -87,8 +86,7 @@ def remove(self, o): raise ValueError() if o not in self._known: return - if o not in self._removed: - self._removed.add(o) + self._removed.add(o) def pop(self): while True: @@ -104,24 +102,6 @@ def pop(self): return o -class SafeSet(set): - """A set that does not raise KeyError when removing non-existent items. - - >>> s = SafeSet() - >>> s.remove(1) - >>> len(s) - 0 - >>> s.remove(1) - """ - - def remove(self, o): - # pylint: disable=missing-return,except-pass - try: - super().remove(o) - except KeyError: - pass - - @total_ordering class ChannelJob(object): """A channel job is attached to a channel and holds the properties of a @@ -408,8 +388,8 @@ def __init__(self, name, parent, capacity=None, sequential=False, throttle=0): self.parent.children[name] = self self.children = {} self._queue = ChannelQueue() - self._running = SafeSet() - self._failed = SafeSet() + self._running = set() + self._failed = set() self._pause_until = 0 # utc seconds since the epoch self.capacity = capacity self.throttle = throttle # seconds @@ -463,8 +443,8 @@ def __str__(self): def remove(self, job): """Remove a job from the channel.""" self._queue.remove(job) - self._running.remove(job) - self._failed.remove(job) + self._running.discard(job) + self._failed.discard(job) if self.parent: self.parent.remove(job) @@ -484,8 +464,8 @@ def set_pending(self, job): """ if job not in self._queue: self._queue.add(job) - self._running.remove(job) - self._failed.remove(job) + self._running.discard(job) + self._failed.discard(job) if self.parent: self.parent.remove(job) _logger.debug("job %s marked pending in channel %s", job.uuid, self) @@ -498,7 +478,7 @@ def set_running(self, job): if job not in self._running: self._queue.remove(job) self._running.add(job) - self._failed.remove(job) + self._failed.discard(job) if self.parent: self.parent.set_running(job) _logger.debug("job %s marked running in channel %s", job.uuid, self) @@ -507,7 +487,7 @@ def set_failed(self, job): """Mark the job as failed.""" if job not in self._failed: self._queue.remove(job) - self._running.remove(job) + self._running.discard(job) self._failed.add(job) if self.parent: self.parent.remove(job) From 5984ecc341d6b52f4e536ade56696de049a2cc92 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Sat, 21 Dec 2024 16:21:52 +0000 Subject: [PATCH 2/2] [BOT] post-merge updates --- README.md | 2 +- queue_job/README.rst | 2 +- queue_job/__manifest__.py | 2 +- queue_job/static/description/index.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7c2f04e1cf..c58c1039e3 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Available addons addon | version | maintainers | summary --- | --- | --- | --- [base_export_async](base_export_async/) | 15.0.1.0.1 | | Asynchronous export with job queue -[queue_job](queue_job/) | 15.0.2.3.11 | [![guewen](https://github.com/guewen.png?size=30px)](https://github.com/guewen) | Job Queue +[queue_job](queue_job/) | 15.0.2.3.12 | [![guewen](https://github.com/guewen.png?size=30px)](https://github.com/guewen) | Job Queue [queue_job_cron](queue_job_cron/) | 15.0.1.0.0 | | Scheduled Actions as Queue Jobs [queue_job_cron_jobrunner](queue_job_cron_jobrunner/) | 15.0.2.0.0 | [![ivantodorovich](https://github.com/ivantodorovich.png?size=30px)](https://github.com/ivantodorovich) | Run jobs without a dedicated JobRunner [queue_job_subscribe](queue_job_subscribe/) | 15.0.1.0.0 | | Control which users are subscribed to queue job notifications diff --git a/queue_job/README.rst b/queue_job/README.rst index 626efc918d..a22f8ad8bb 100644 --- a/queue_job/README.rst +++ b/queue_job/README.rst @@ -7,7 +7,7 @@ Job Queue !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:c6803b0e13920b60d7c2c1b8c78a8efa67ecc1d24a4ce8ff8ec835b8b07ad987 + !! source digest: sha256:273ee23baedfd996e4827a938bd5cd55a7d38f711b36e180dbd35ec55167b94b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png diff --git a/queue_job/__manifest__.py b/queue_job/__manifest__.py index 6177258ca7..43850ac203 100644 --- a/queue_job/__manifest__.py +++ b/queue_job/__manifest__.py @@ -2,7 +2,7 @@ { "name": "Job Queue", - "version": "15.0.2.3.11", + "version": "15.0.2.3.12", "author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/queue", "license": "LGPL-3", diff --git a/queue_job/static/description/index.html b/queue_job/static/description/index.html index f8de7849d5..bcd8f0580b 100644 --- a/queue_job/static/description/index.html +++ b/queue_job/static/description/index.html @@ -367,7 +367,7 @@

Job Queue

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:c6803b0e13920b60d7c2c1b8c78a8efa67ecc1d24a4ce8ff8ec835b8b07ad987 +!! source digest: sha256:273ee23baedfd996e4827a938bd5cd55a7d38f711b36e180dbd35ec55167b94b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Mature License: LGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

This addon adds an integrated Job Queue to Odoo.