I am using CRON UI on my website to create re-occurring schedule for some users task. The UI generates CRON format which is stored in database and i am looking for a way to get the Next run time to know if the task is due and execute that accordingly. Is there a way i can convert the CRON format to get the next run time in SQL?
0 9 1-7 * 1 * First Monday of each month, at 9 a.m.
0 0 1 * * * At midnight, on the first day of each month
* 0-11 * * * Each minute before midday
TABLE
JobID, CRONSchedule
1 0 9 1-7 * 1 *
2 0 0 1 * * *
3 * 0-11 * * *
SQL
Select JobID, CRONSchedule, NextRunTime from TABLE
1条答案
按热度按时间gopyfrb31#
I have used this query to determine whether a particular cron is ready to run (Returns t/f). Based on this query you can get the next run date & time, update columns present in the table in the table and can do various such jobs. But this code comes with limitations, we can only enter cron data with a 5-digit structure.
This is going to be my table structure
I hope that this code was helpful!!