dragonmantank / cron-expression

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
MIT License
4.54k stars 121 forks source link

Support for (optional) Seconds Field #166

Open rumpfc opened 12 months ago

rumpfc commented 12 months ago

There are some use cases where cron tasks have to run more than once per minute. It might not be support for Linux crons, but frameworks with internal scheduling features (i.e. Java Spring Boot) support or require a Seconds field.

10 5 * * * (5 fields) would mean trigger every day at 05:10:00 am 0 10 5 * * * (6 fields) also means trigger every day at 05:10:00 am * 10 5 * * * (6 fields) means trigger every day between 05:10:00 am and 05:10:59 am every second

6 field parsing should be optional for backwards compatibility.

mabar commented 6 months ago

And sometimes there is instead field for year (there was one in v1 of this library). Or both. Compatibility nightmare. Also, crontab usually runs few seconds late and some jobs would never match. I've implemented simplified version of this feature outside of cron expression in orisai/scheduler to repeat job every few seconds. Scheduler in Laravel also has the same feature, but it's coupled with the whole framework, not an independent library.