January 29, 2021
I had a queued job that I wanted to run every thirty minutes, but only during the daytime.
Turns out that Laravel has two methods that allow you to control the times of day that a scheduled job is executed: between
and unlessBetween
.
// file: app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
// Only runs between 7 a.m. and 11 p.m.
$schedule->job(new App\Jobs\SomeJob)
->everyThirtyMinutes()
->between('7:00', '23:00');
// Runs at all times except from 2 a.m. to 8 a.m.
$schedule->job(new App\Jobs\SomeJob)
->everyThirtyMinutes()
->unlessBetween('2:00', '8:00');
}
You can do the same things with either method, so it's up to you to pick whichever one feels better.
Tufts Meal Plan Wrapped
Mar 2, 2024
Building an e-ink picture frame that displays an iCloud photo album
Jan 9, 2024
2023 in review
Jan 5, 2024
Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iām working on!