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
2 changes: 1 addition & 1 deletion queue_job_batch/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=True)

@api.model_create_multi
def create(self, vals_list):
Expand Down
28 changes: 22 additions & 6 deletions queue_job_batch/models/queue_job_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,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):
Expand Down
Loading