From a84cb451415e4e9d792596fde60d18a55e1f0e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 3 Apr 2024 16:30:46 +0200 Subject: [PATCH] Compute next call of cron task using actual now If the cron task took more time then the repeating delay, it is not useful to reschedule it in the past. --- trytond/trytond/ir/cron.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/trytond/trytond/ir/cron.py b/trytond/trytond/ir/cron.py index ccea060e73..eb82f25b9a 100644 --- a/trytond/trytond/ir/cron.py +++ b/trytond/trytond/ir/cron.py @@ -123,7 +123,9 @@ class Cron(DeactivableMixin, ModelSQL, ModelView): }), ] - def compute_next_call(self, now): + def compute_next_call(self, now=None): + if now is None: + now = datetime.datetime.now() return (now.replace(tzinfo=tz.UTC).astimezone(tz.SERVER) + relativedelta(**{self.interval_type: self.interval_number}) + relativedelta( @@ -210,7 +212,7 @@ class Cron(DeactivableMixin, ModelSQL, ModelView): task.lock() with processing(name): task.run_once() - task.next_call = task.compute_next_call() + task.next_call = task.compute_next_call(now) task.save() logger.info("%s in %i ms", name, duration()) except Exception as e: