MonthlyOn() 可以在 laravel 调度程序中使用吗?
我制作了一个自定义命令,并希望它在上个月的最后一天 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。
I have made a custom command and want it to run on month last day at 02:00 but I also want it to run after that between some period of time like 02:00 till 15:00 following is my scheduler
`$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00");`
now what I think Ill do to achieve this is like this:
$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00")
->between("02:00", "15:00");
will it work as I want? I am on laravel version 6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 Laravel 6 时,您可以安排命令每天运行,但只需检查当天是否是该月的最后一天,如下所示:
如果您使用的是较新版本的 Laravel,您可以使用
lastDayOfMonth< /code> 您可以提供一个时间,如果需要,您还可以在其上链接
Between
。另外,为了实现您想要的目标,您可以指定 2 个计划并解决问题。
应该是这样的:
As you are on Laravel 6, you can schedule your command to run every day, but just check is that day the last day of the month, something like this:
If you are on newer versions of Laravel you can use
lastDayOfMonth
to which you can provide a time, and if needed, you can also chainbetween
on it.Also, to achieve what you want, you can specify 2 schedules and resolve the problem.
It should be like this: