Skip to content

Commit 84085d3

Browse files
author
Julien Ortet
committed
[18][UPD] add empty batch remove when job vaccum
1 parent 81adf54 commit 84085d3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

queue_job_batch/models/queue_job.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ def write(self, vals):
3030
# to work with the same batch
3131
batch.with_delay(identity_key=identity_exact).check_state()
3232
return super().write(vals)
33+
34+
def autovacuum(self):
35+
"""Delete batches if all jobs are unlink after job autovacuum
36+
Called from a cron.
37+
"""
38+
39+
ret = super().autovacuum()
40+
batches = self.env["queue.job.batch"].search([("job_ids", "=", False)])
41+
42+
for batch in batches:
43+
if not batch.job_ids:
44+
batch.unlink()
45+
46+
return ret

0 commit comments

Comments
 (0)