monthlyOn() 在 laravel 调度程序中与 between 一起工作吗?
does monthlyOn() works with between in laravel scheduler?
我已经创建了一个自定义命令,并希望它在一个月的最后一天 02:00 运行 但我也希望它在那之后的某个时间段之间 运行 02:00 到 15:00 以下是我的调度程序
`$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00");`
现在我想我会做的是这样的:
$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00")
->between("02:00", "15:00");
它会如我所愿吗?我在 laravel 版本 6.
当你在 Laravel 6 时,你可以将命令安排到每天 运行,但只需检查那一天是该月的最后一天,如下所示:
// Runs exactly on "02:00" every month on its last day.
// (Actually runs every day, but doesn't execute if the day is not the last day of the month).
$schedule->command('billing:generate')->dailyAt('02:00')->when(function () {
return Carbon::now()->endOfMonth()->isToday();
});
// Runs between "02:00" and "15:00" every month on its last day.
// (Actually runs every day, but doesn't execute if the day is not the last day of the month).
$schedule->command('billing:generate')->daily()->between("02:00", "15:00")->when(function () {
return Carbon::now()->endOfMonth()->isToday();
});
如果您使用的是 Laravel 的较新版本,您可以使用 lastDayOfMonth
来提供时间,如果需要,您还可以在其上链接 between
。
另外,为了达到你想要的效果,你可以指定2个时间表并解决问题。
应该是这样的:
// Runs exactly on "02:00" every month on its last day.
$schedule->command('billing:generate')->lastDayOfMonth("02:00");
// Runs between "02:00" and "15:00" every month on its last day.
$schedule->command('billing:generate')->lastDayOfMonth()->between("02:00", "15:00");
我已经创建了一个自定义命令,并希望它在一个月的最后一天 02:00 运行 但我也希望它在那之后的某个时间段之间 运行 02:00 到 15:00 以下是我的调度程序
`$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00");`
现在我想我会做的是这样的:
$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00")
->between("02:00", "15:00");
它会如我所愿吗?我在 laravel 版本 6.
当你在 Laravel 6 时,你可以将命令安排到每天 运行,但只需检查那一天是该月的最后一天,如下所示:
// Runs exactly on "02:00" every month on its last day.
// (Actually runs every day, but doesn't execute if the day is not the last day of the month).
$schedule->command('billing:generate')->dailyAt('02:00')->when(function () {
return Carbon::now()->endOfMonth()->isToday();
});
// Runs between "02:00" and "15:00" every month on its last day.
// (Actually runs every day, but doesn't execute if the day is not the last day of the month).
$schedule->command('billing:generate')->daily()->between("02:00", "15:00")->when(function () {
return Carbon::now()->endOfMonth()->isToday();
});
如果您使用的是 Laravel 的较新版本,您可以使用 lastDayOfMonth
来提供时间,如果需要,您还可以在其上链接 between
。
另外,为了达到你想要的效果,你可以指定2个时间表并解决问题。
应该是这样的:
// Runs exactly on "02:00" every month on its last day.
$schedule->command('billing:generate')->lastDayOfMonth("02:00");
// Runs between "02:00" and "15:00" every month on its last day.
$schedule->command('billing:generate')->lastDayOfMonth()->between("02:00", "15:00");