自定义日的任务安排 Laravel
Task Scheduling on custom day Laravel
我只想在这几天做这份工作,我可以使用 at() 和 when() 吗????
$schedule->command('mycommand')->when(function () {
$day = Carbon::today()->day;
if($day == 3 || $day == 5 || $day == 7 || $day == 22) {
return true;
} else {
return false;
}
})->at('17:00');
您可以在特定日期重复多个月度运行
$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');
希望对您有所帮助
你可以这样使用:
$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');
或者,更简单的方法,使用 cron :
$schedule->command('mycommand')->cron('0 17 3,5,7,22 * *');
我只想在这几天做这份工作,我可以使用 at() 和 when() 吗????
$schedule->command('mycommand')->when(function () {
$day = Carbon::today()->day;
if($day == 3 || $day == 5 || $day == 7 || $day == 22) {
return true;
} else {
return false;
}
})->at('17:00');
您可以在特定日期重复多个月度运行
$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');
希望对您有所帮助
你可以这样使用:
$schedule->command('mycommand')->monthlyOn(3, '17:00');
$schedule->command('mycommand')->monthlyOn(5, '17:00');
$schedule->command('mycommand')->monthlyOn(7, '17:00');
$schedule->command('mycommand')->monthlyOn(22, '17:00');
或者,更简单的方法,使用 cron :
$schedule->command('mycommand')->cron('0 17 3,5,7,22 * *');