How I write my Scheduled Actions
In Laravel there is a great scheduler built in.
You need to run a OS based job that calls a console action every minute
php artisan schedule:run
This works great, and various functions allow you to run your scheduled actions at pretty much any interval you want.
I currently use scheduler to
Check for bookings every minute during the day
Check for bookings every 10 minutes at night.
Clear up cache directories once a day
Prune models every day.
Send out student emails at a specific time daily.
However I find that putting information into the schedule method of the console Kernal to be not the best place to put this info. For one thing when searching I type 'schedule' but that wont find my file so it seems like the wrong place.
instead what I do is create a Scheduler class and place it in the Consol directory with a single method
public function schedule (Schedule $schedule)
inside this I can reference the $schedule object and call all my schedules
public static function run(Schedule $schedule) { // Ensure we are logged in as a system user. User::LoginSystemUser(); //Log::debug('Schedule:'); Self::CheckInternetBookings($schedule); $schedule->call(new RemoveSpacesFromNames)->name('Remove Space from front of names')->everyThirtyMinutes(); $schedule->call(new ChangeUpperCaseName)->name('Changes Upper Case Names to Mixed Case')->everyThirtyMinutes(); $schedule->call(new UpdateNullAccommodation)->name('Update Accommodation 1900 to null') ->everyThirtyMinutes(); .... }
and I just need to this in the kernel
protected function schedule(Schedule $schedule) { Scheduler::run($schedule); }
I find that this is a much better layout. Hope this is helpful
















