Skip to content

Commit d05b1f3

Browse files
authored
Merge pull request #579 from chengshifan/fix-cron
chore: fix cronjob last triggger not up to date
2 parents e1f5426 + a7daa0d commit d05b1f3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/scheduler/kubernetes/scheduler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,20 @@ def handle_cron_jobs(self):
993993
# still in future
994994
continue
995995

996+
# Double-check the next_trigger by selecting the latest last_trigger for the cronjob
997+
cursor.execute("""
998+
SELECT last_trigger
999+
FROM cronjob
1000+
WHERE id = %s """, [c['id']])
1001+
result = cursor.fetchone()
1002+
if result:
1003+
last_trigger = result['last_trigger']
1004+
i = croniter('%s %s %s %s %s' % (c['minute'], c['hour'], c['day_month'], c['month'], c['day_week']), last_trigger)
1005+
next_trigger = i.get_next(datetime)
1006+
if next_trigger > datetime.now():
1007+
# still in future
1008+
continue
1009+
9961010
cursor.execute('''
9971011
UPDATE cronjob
9981012
SET last_trigger = now()

0 commit comments

Comments
 (0)