在 laravel 时间间隔安排作业

Schedule job in laravel time interval

我在 Kernel.php 每小时有三个计划作业,如下所示:

$schedule->command('get:twitter')->cron('* 1 * * * *');
$schedule->command('get:facebook')->cron('* 1 * * * *');
$schedule->command('get:googleplus')->cron('* 1 * * * *');

我想运行这三个时间间隔如下:

$schedule->command('get:twitter')->cron('* 1 * * * *');//after 1 hour
$schedule->command('get:facebook')->cron('30 1 * * * *');//after 1.30 hour
$schedule->command('get:googleplus')->cron('45 1 * * * *');//after 1.45 hour

这在 laravel 5.1

中可能吗

没有开箱即用的东西,但您可以这样做:

// every hour
$schedule->command('get:twitter')->hourly();

// every one and a half hours
$schedule->command('get:facebook')->cron('0 0,3,6,9,12,15,18,21 * * * *');
$schedule->command('get:facebook')->cron('30 1,4,7,10,13,16,19,22 * * * *');

// every two hours at x.15 minutes (0.15, 2.15, 4.15 etc)
$schedule->command('get:googleplus')->cron('15 */2 * * * *');

最近 Laravel 更新后,您可以 运行 如下所示:

// Run the task every hour at 17 minutes past the hour
$schedule->command('emails:send')->hourly(17);

https://laravel.com/docs/8.x/scheduling#schedule-frequency-options