diff --git a/README.md b/README.md index 979d94d524..48ce68f2d8 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ 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.3.1.3 | guewen sbidoul | Job Queue -[queue_job_batch](queue_job_batch/) | 18.0.1.0.0 | | Job Queue Batch +[queue_job_batch](queue_job_batch/) | 18.0.1.1.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.1 | ivantodorovich | Run jobs without a dedicated JobRunner [queue_job_profiler](queue_job_profiler/) | 18.0.1.0.1 | simahawk | Job Queue Profiler diff --git a/queue_job_batch/README.rst b/queue_job_batch/README.rst index d0b9d22c38..a232be0b3c 100644 --- a/queue_job_batch/README.rst +++ b/queue_job_batch/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + =============== Job Queue Batch =============== @@ -7,13 +11,13 @@ Job Queue Batch !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:b6e605728ea05be0bf98dbe6e94c197bab21882e965286ef214f719e252b444e + !! source digest: sha256:81d1edb81bb2c114b7afe11730c4f36f6eedcf5fe32a6b258600fd24d69a4be9 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github diff --git a/queue_job_batch/__manifest__.py b/queue_job_batch/__manifest__.py index 669ba10927..fc1245e076 100644 --- a/queue_job_batch/__manifest__.py +++ b/queue_job_batch/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Job Queue Batch", - "version": "18.0.1.0.0", + "version": "18.0.1.1.0", "author": "Creu Blanca,Odoo Community Association (OCA)", "website": "https://github.com/OCA/queue", "license": "AGPL-3", diff --git a/queue_job_batch/models/queue_job.py b/queue_job_batch/models/queue_job.py index ddc3efe879..524da23ef7 100644 --- a/queue_job_batch/models/queue_job.py +++ b/queue_job_batch/models/queue_job.py @@ -9,7 +9,7 @@ class QueueJob(models.Model): _inherit = "queue.job" - job_batch_id = fields.Many2one("queue.job.batch") + job_batch_id = fields.Many2one("queue.job.batch", index="btree_not_null") @api.model_create_multi def create(self, vals_list): diff --git a/queue_job_batch/models/queue_job_batch.py b/queue_job_batch/models/queue_job_batch.py index 998f7a5ac2..a0d084040d 100644 --- a/queue_job_batch/models/queue_job_batch.py +++ b/queue_job_batch/models/queue_job_batch.py @@ -62,9 +62,11 @@ class QueueJobBatch(models.Model): compute="_compute_job_count", ) - def _get_state(self): - self.ensure_one() - job_states = set(self.job_ids.grouped("state").keys()) + def _get_state(self, job_states): + """Determine the batch state from a set of job states. + + :param job_states: set of state strings for all jobs in this batch + """ if all(state in ("done", "cancelled", "failed") for state in job_states): return "finished" elif {"done", "started"} & job_states: @@ -74,8 +76,20 @@ def _get_state(self): return "pending" def check_state(self): + grouped = self.env["queue.job"].read_group( + [("job_batch_id", "in", self.ids)], + ["job_batch_id", "state"], + ["job_batch_id", "state"], + lazy=False, + ) + states_by_batch = {} + for g in grouped: + batch_id = g["job_batch_id"][0] + states_by_batch.setdefault(batch_id, set()).add(g["state"]) + for rec in self: - if (state := rec._get_state()) != rec.state: + job_states = states_by_batch.get(rec.id, set()) + if (state := rec._get_state(job_states)) != rec.state: rec.state = state def set_read(self): @@ -101,13 +115,29 @@ def get_new_batch(self, name, **kwargs): @api.depends("job_ids.state") def _compute_job_count(self): + grouped = self.env["queue.job"].read_group( + [("job_batch_id", "in", self.ids)], + ["job_batch_id", "state"], + ["job_batch_id", "state"], + lazy=False, + ) + counts = {} + for g in grouped: + batch_id = g["job_batch_id"][0] + counts.setdefault(batch_id, {}) + counts[batch_id][g["state"]] = g["__count"] + for rec in self: - jobs_by_state = rec.job_ids.grouped("state") - rec.job_count = len(rec.job_ids) - rec.failed_job_count = len(jobs_by_state.get("failed", [])) - rec.finished_job_count = len(jobs_by_state.get("done", [])) - rec.completeness = rec.finished_job_count / max(1, rec.job_count) - rec.failed_percentage = rec.failed_job_count / max(1, rec.job_count) + by_state = counts.get(rec.id, {}) + total = sum(by_state.values()) + done = by_state.get("done", 0) + failed = by_state.get("failed", 0) + + rec.job_count = total + rec.failed_job_count = failed + rec.finished_job_count = done + rec.completeness = done / max(1, total) + rec.failed_percentage = failed / max(1, total) @api.model def _to_store_fnames(self): diff --git a/queue_job_batch/static/description/index.html b/queue_job_batch/static/description/index.html index 455c0ecf78..75a507f02e 100644 --- a/queue_job_batch/static/description/index.html +++ b/queue_job_batch/static/description/index.html @@ -3,7 +3,7 @@ -Job Queue Batch +README.rst -
-

Job Queue Batch

+
+ + +Odoo Community Association + +
+

Job Queue Batch

-

Beta License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

This addon adds an a grouper for queue jobs.

It allows to show your jobs in a batched form in order to know better the results.

Example:

-from odoo import models, fields, api
+from odoo import models, fields, api
 
 
-class MyModel(models.Model):
+class MyModel(models.Model):
     _name = 'my.model'
 
-    def my_method(self, a, k=None):
+    def my_method(self, a, k=None):
         _logger.info('executed with a: %s and k: %s', a, k)
 
 
-class MyOtherModel(models.Model):
+class MyOtherModel(models.Model):
     _name = 'my.other.model'
 
     @api.multi
-    def button_do_stuff(self):
+    def button_do_stuff(self):
         batch = self.env['queue.job.batch'].get_new_batch('Group')
         model = self.env['my.model'].with_context(job_batch=batch)
         for i in range(1, 100):
@@ -415,13 +420,13 @@ 

Job Queue Batch

-

Usage

+

Usage

You can manage your batch jobs from the Systray. A new button will be shown with your currently executing job batches and the recently finished job groups.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub 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 @@ -429,15 +434,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Creu Blanca
-

Contributors

+

Contributors

-

Other credits

+

Other credits

The migration of this module from 12.0 to 14.0 was financially supported by Camptocamp

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -475,5 +480,6 @@

Maintainers

+