From 9427804ef436d10641dcab28c2dde6acea3d112e Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 24 Mar 2021 13:57:39 +0000 Subject: [PATCH] [FIX] ir.cron: execute jobs in priority order (again) The selection mechanism selects 1 job at a time from the jobs that are ready to execute, but while doing this it should respect the `priority` defined on the jobs. Otherwise the field is useless, and the user has no way to ensure that a long-running job does not cause starvation. (Assuming execution resources that are insufficient for 100% of the processing to happen) The `priority` ordering was apparently lost during the introduction of the trigger mechanism in #62124 via 4b28f1162a85d03f9dbe0338b06758ad151ea6a8. It was previously taken into account in `_process_jobs()`. The `ORDER BY` is not strictly necessary in `_get_all_ready_jobs()`, but it seems more consistent for this method to return an ordered list as well, given the semantics of the `priority` field. We don't know what the caller will do with the result. closes odoo/odoo#68411 X-original-commit: 9d570662b4016b5cd9ad3c85abbcb5428c169cc6 Signed-off-by: Olivier Dony (odo) --- odoo/addons/base/models/ir_cron.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/odoo/addons/base/models/ir_cron.py b/odoo/addons/base/models/ir_cron.py index c4a4e7b5791..9bfe0b6cefe 100644 --- a/odoo/addons/base/models/ir_cron.py +++ b/odoo/addons/base/models/ir_cron.py @@ -179,6 +179,7 @@ class ir_cron(models.Model): WHERE call_at <= (now() at time zone 'UTC') ) ) + ORDER BY priority """) return cr.dictfetchall() @@ -224,6 +225,7 @@ class ir_cron(models.Model): ) ) AND id in %s + ORDER BY priority LIMIT 1 FOR NO KEY UPDATE SKIP LOCKED """, [job_ids]) return cr.dictfetchone()