Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel scheduler timezone

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'));
}
like image 763
Petah Avatar asked Jan 14 '16 22:01

Petah


People also ask

How does the laravel scheduler work?

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.

How do I schedule a cron job in laravel?

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.

How do I know if laravel Task Scheduler is running?

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.


1 Answers

You can do it using timezone() method:

$schedule->command('run-report')->weekly()->mondays()->at('12:00')->timezone('Pacific/Auckland');
like image 125
jedrzej.kurylo Avatar answered Sep 23 '22 16:09

jedrzej.kurylo