How do I set the Laravel scheduler to run a task at a specific time in a certain timezone? The server is set to UTC, but I want to run the task at 12 noon every Monday in the Pacific/Auckland
timezone.
E.g. this will work, but the timezone is UTC:
protected function schedule(Schedule $schedule) {
$schedule->command('run-report')->weekly()->mondays()->at('12:00'));
}
The scheduler allows you to fluently and expressively define your command schedule within your Laravel application itself. When using the scheduler, only a single cron entry is needed on your server. Your task schedule is defined in the app/Console/Kernel.php file's schedule method.
To achieve this, Cron uses the specific configuration file called 'crontab', also known as 'Cron Table', to manage the scheduling process. Cron jobs are composed of two parts, the Cron expression, and a shell command that needs to be run. Cron expression is used for setting the schedule frequency.
Well one of the way can test if Schedule is running you can dump anything to log file. Log::info('Schedule Running '. \Carbon\Carbon::now()); After that you can grep the message from Logs.
You can do it using timezone() method:
$schedule->command('run-report')->weekly()->mondays()->at('12:00')->timezone('Pacific/Auckland');
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