我在不同的主机上维护一个应用程序(基于 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
}
}
}
在您的
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');
}
}
关于php - 有没有办法检查 Laravel 计划是否正在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54491604/