我在Laravel做了我的第一个cron。我在我的项目中使用Laravel 9。我有一个命令,我需要在每个星期日和星期六的午夜运行。
我写这个代码:
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param IlluminateConsoleSchedulingSchedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('recycler:update')
->sundays()
->saturdays()
->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
这个配置正确吗?
当我运行命令从artisan: php工匠回收器:更新-它的工作很好。现在我需要从cron运行这个:)
我试着这样设置:
$schedule->command('recycler:update')
->weekends()
->at(00:00);
As weekends()方法将事件安排为仅在周六和周日运行。此外,您希望只在午夜运行它,而不是每小时运行一次。
你可以检查你的日程任务运行:
php artisan schedule:list