I know we can specify certain tasks for every X
individual times like following will run after every two hours:
$schedule->command('catalog:update')->cron('0 */2 * * *');
However, I need to run every two hour but still be able to exclude certain times. For example, Scheduler should run my task every two hours but not between these times: 12 am to 5 am
I was thinking of putting current time check login in task itself which might work. Is there any other better or laravel-specific way of doing it ?
Thanks for the help/suggestions
Use Laravel Scheduler with hourly()
and unlessBetween()
.
The
unlessBetween
method can be used to exclude the execution of a task for a period of time
An example:
->hourly()->unlessBetween('00:00', '5:00');
https://laravel.com/docs/5.5/scheduling#schedule-frequency-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With