peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
811 stars 144 forks source link

Run every X minutes #75

Closed dhaarbrink closed 5 years ago

dhaarbrink commented 5 years ago

There are some jobs I would like to schedule every x minutes. I figured I could do it with ->everyMinute(5) or maybe ->hourly('*/5') but both aren't supported.

The latter could work if validateCronRange() is fixed to support it.

For now I use this workaround: ->at('*/5 * * * *'). But it is ugly, and kind of defeats the purpose of using an interface for scheduling.

I would think this is a common enough usage to be supported by the interface.

nikolee commented 5 years ago

->everyMinute(5) is a more elegant syntax rather than:

$runtime = array(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55); foreach ($runtime as $timer) { $scheduler->php('/path/to/the/job/php')->hourly($timer); }

mtalha91 commented 5 years ago

I used $object->at('42 ') to run cron job after every 42 minutes. But when the cron job is run, it is run more than one time.

For example. A cron job is scheduled at every 42 minutes. When the time came, the cron job runs at the exact time but also multiples time.

Any help would be appreciated.

dhaarbrink commented 5 years ago

@peppeocchi I took the liberty to write a patch for this feature: https://github.com/peppeocchi/php-cron-scheduler/pull/82. Could you please review? Thanks.