Dew*_*159 4 php scheduled-tasks laravel
我在不同的主机上维护一个应用程序(基于 Laravel 构建)的多个副本,并且我正在寻找一种方法来检查 Laravel Schedule 是否确实为每个应用程序运行。Laravel 是否为此提供了一些东西?
我遇到了同样的问题,并通过使用命令中的选项修复了它:
class SomeCommand extends Command
{
protected $signature = 'some:command {--other-option} {--schedule}';
public function handle()
{
if ($this->option('schedule')) {
// this command is triggered by the schedule
}
}
}
Run Code Online (Sandbox Code Playgroud)
在你的app/Console/Kernel.php:
class Kernel extends ConsoleKernel
{
/**
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*/
protected function schedule(Schedule $schedule)
{
$schedule->command(SomeCommand::class, ['--schedule'])->hourly();
}
protected function commands()
{
$this->load(__DIR__ . '/Commands');
}
}
Run Code Online (Sandbox Code Playgroud)