Skip to content

Instantly share code, notes, and snippets.

@einnar82
Created February 12, 2020 01:31
Show Gist options
  • Save einnar82/93a6c070bf5092d7a645256f2e5986b8 to your computer and use it in GitHub Desktop.
Save einnar82/93a6c070bf5092d7a645256f2e5986b8 to your computer and use it in GitHub Desktop.
Best Practice when using Laravel Schedule
<?php
namespace App\Console;
use App\Console\Commands\SendRemcoDTRCommand;
use App\Modules\USP\Jobs\Remco\RemcoDTRJob;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\SendRemcoDTRCommand'
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
/**
* Common mistakes when using laravel task scheduling is the proper execution time of task.
* Some developers experiencing “No scheduled commands are ready to run.” error when running the scheduler.
* I've discovered that there is a format when executing task schedule,
*
* $frequencyOptions = 'https://laravel.com/docs/6.x/scheduling#schedule-frequency-options';
* $scheduleConstraints = 'schedule constraints';
*
* $schedule->job()->{$frequencyOptions}->{$scheduleConstraints};
*/
$schedule->command('send:remco-dtr')->dailyAt('09:30')->timezone('Asia/Manila');
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__ . '/Commands');
include base_path('routes/console.php');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment