contributte / scheduler

:hourglass: PHP job scheduler (cron) with locking for Nette Framework
https://contributte.org/packages/contributte/scheduler.html
MIT License
30 stars 10 forks source link

Last-run feature #23

Closed elektro-potkan closed 2 years ago

elektro-potkan commented 3 years ago

Hello all,

I cannot always run the scheduler each minute, so I was missing the option to run the jobs during the next run.

I have added into LockingScheduler the ability to store last-run timestamp (heavily inspired by baraja-core/cronner, but only scheduler-level, as I do not need it in the job-level). I have used this scheduler as it already has configured a directory for storing its locks. If I should implemented it in a separate Scheduler, please, let me know.

Due to this, a change in the IJob definition was needed. If it should be done backward-compatible (though the package is in 0.x version), I could reimplement it using another interface.

The documentation is not edited (yet, would like to hear from You first).

Thank You for Your response.

Best regards

f3l1x commented 3 years ago

Hi, I miss the point of this change. What do you mean with so I was missing the option to run the jobs during the next run?

elektro-potkan commented 3 years ago

Hi @f3l1x,

the point is, that if the scheduler's run method (in current implementation) is called approximately each 15 minutes (so it is not called at some precise time), it will sometime (or in most cases, it depends) call the job's isDue method before and after the right time. As the ExpressionJob is simply calling Cron\CronExpression::isDue, the job might never run. To reliably run in such environment, it should also check for the condition described above and in such case return true even when called after the right time. But it needs to know the previous time it was called - and I think, the scheduler should supply it with such an information (instead of implementing the timestamp load/save in each job).

f3l1x commented 2 years ago

I've looked at your fork. Seems it's working for you and you've added more features. Keep it this way and I am closing it here.

f3l1x commented 2 years ago

Thank you for your work on that.