首页 > 解决方案 > 有没有办法检查 Laravel 计划是否正在运行?

问题描述

我在不同的主机上维护一个应用程序(基于 Laravel 构建)的多个副本,并且我正在寻找一种方法来检查 Laravel Schedule 是否真的为每个应用程序运行。Laravel 是否为此提供了一些东西?

标签: phplaravelscheduled-tasks

解决方案


我有同样的问题,并通过在我的命令中使用一个选项来修复它:

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');
    }
}

推荐阅读