From 70284e42e2b64d465e53b0c93a8d2937aec87e1e Mon Sep 17 00:00:00 2001 From: chengshifan <545591082@qq.com> Date: Thu, 23 May 2024 15:31:22 +0800 Subject: [PATCH] fix cron --- src/scheduler/kubernetes/scheduler.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/scheduler/kubernetes/scheduler.py b/src/scheduler/kubernetes/scheduler.py index 5d568632..20cec847 100644 --- a/src/scheduler/kubernetes/scheduler.py +++ b/src/scheduler/kubernetes/scheduler.py @@ -989,6 +989,18 @@ def handle_cron_jobs(self): next_trigger = i.get_next(datetime) + if next_trigger > datetime.now(): + # still in future + continue + + # Double-check the next_trigger by selecting the latest last_trigger for the cronjob + cursor.execute(""" + SELECT last_trigger + FROM cronjob + WHERE id = %s """, [c['id']]) + last_trigger = cursor.fetchone() + i = croniter('%s %s %s %s %s' % (c['minute'], c['hour'], c['day_month'], c['month'], c['day_week']), last_trigger) + next_trigger = i.get_next(datetime) if next_trigger > datetime.now(): # still in future continue