Laravel任务调度命令频率延迟或偏移
Laravel task scheduling command frequency delay or offset
有没有办法从建议的频率选项中延迟或偏移预定命令?
例如:
$schedule->command('GetX')->everyTenMinutes(); --> run at 9:10, 9:20, 9:30
$schedule->command('GetY')->everyTenMinutes(); --> run at 9:15, 9:25, 9:35
调度任务时没有delay
功能。
但是when
方法可以用来每10分钟安排一个任务,延迟5分钟:
// this command is scheduled to run if minute is 05, 15, 25, 35, 45, 55
// the truth test is checked every minute
$schedule->command('foo:bar')->everyMinute()->when(function () {
return date('m') - 5 % 10 == 0;
});
按照这个规则,可以每隔x分钟安排一个任务,延迟y分钟
$schedule->command('foo:bar')->everyMinute()->when(function () {
return date('m') - y % x == 0;
});
如果遇到困难,您可以直接编写自定义 Cron 计划的直接方法。以后看代码的时候更容易理解,不会头疼。
$schedule->command('foo:bar')->cron('05,15,25,35,45,55 * * * *');
有没有办法从建议的频率选项中延迟或偏移预定命令?
例如:
$schedule->command('GetX')->everyTenMinutes(); --> run at 9:10, 9:20, 9:30
$schedule->command('GetY')->everyTenMinutes(); --> run at 9:15, 9:25, 9:35
调度任务时没有delay
功能。
但是when
方法可以用来每10分钟安排一个任务,延迟5分钟:
// this command is scheduled to run if minute is 05, 15, 25, 35, 45, 55
// the truth test is checked every minute
$schedule->command('foo:bar')->everyMinute()->when(function () {
return date('m') - 5 % 10 == 0;
});
按照这个规则,可以每隔x分钟安排一个任务,延迟y分钟
$schedule->command('foo:bar')->everyMinute()->when(function () {
return date('m') - y % x == 0;
});
如果遇到困难,您可以直接编写自定义 Cron 计划的直接方法。以后看代码的时候更容易理解,不会头疼。
$schedule->command('foo:bar')->cron('05,15,25,35,45,55 * * * *');