Skip to content

Commit 4aca6cc

Browse files
committed
[IMP] queue_job_batch: Add batch execution_time field.
This also adds an _on_finished hook that retries until the entire batch is complete.
1 parent 879d1a7 commit 4aca6cc

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

queue_job_batch/models/queue_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def write(self, vals):
2525
for record in self:
2626
if record.state != "done" and record.job_batch_id:
2727
batches |= record.job_batch_id
28-
for batch in batches:
28+
for batch in batches.with_context(job_batch=None):
2929
# We need to make it with delay in order to prevent two jobs
3030
# to work with the same batch
3131
batch.with_delay(identity_key=identity_exact).check_state()

queue_job_batch/models/queue_job_batch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from odoo import api, fields, models
66

77
from odoo.addons.mail.tools.discuss import Store
8+
from odoo.addons.queue_job.exception import RetryableJobError
89

910

1011
class QueueJobBatch(models.Model):
@@ -58,6 +59,7 @@ class QueueJobBatch(models.Model):
5859
completeness = fields.Float(
5960
compute="_compute_job_count",
6061
)
62+
execution_time = fields.Float(compute="_compute_job_count")
6163
failed_percentage = fields.Float(
6264
compute="_compute_job_count",
6365
)
@@ -107,8 +109,13 @@ def _compute_job_count(self):
107109
rec.failed_job_count = len(jobs_by_state.get("failed", []))
108110
rec.finished_job_count = len(jobs_by_state.get("done", []))
109111
rec.completeness = rec.finished_job_count / max(1, rec.job_count)
112+
rec.execution_time = sum(rec.job_ids.mapped("exec_time"))
110113
rec.failed_percentage = rec.failed_job_count / max(1, rec.job_count)
111114

115+
def _on_finished(self):
116+
if self.state != "finished":
117+
raise RetryableJobError(f"{self.name} {100.0 * self.completeness}%")
118+
112119
@api.model
113120
def _to_store_fnames(self):
114121
return (

queue_job_batch/views/queue_job_batch_views.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
options="{'current_value': 'finished_job_count', 'max_value': 'job_count'}"
1515
/>
1616
<field name="state" />
17+
<field name="execution_time" />
1718
</list>
1819
</field>
1920
</record>

0 commit comments

Comments
 (0)