Laravel 5.5作业链:调用未定义的方法:: chain()

时间:2018-04-19 08:00:21

标签: laravel-5.5 laravel-jobs

我有两个工作,第一个需要在运行之前发送第二个,我发现工作链但不能使它工作,所有工作都是从框中设置的,所以从理论上说它应该工作。 这是我的第一份工作:

namespace App\Jobs;

class MCSendJob
{
    use Dispatchable, InteractsWithQueue;

    public function handle(Config $config, MCReport $report)
    {
        if ($config->mcdb_status) {
            $report->setConnection('mcdb');
        } elseif ($config->rmcdb_status) {
            $report->setConnection('rmcdb');
        } else {
            $this->fail(new \Exception('No active MCDB connection found!'));
        }

        $models = collect([
            'appoitments' => Appointment::sent(false)->get(),
            'questions' => Question::sent(false)->get(),
            'price-clarifications' => PriceClarification::sent(false)->get(),
        ])->flatten(1);

        foreach ($models as $model) {
            $report->fill((new MCResource($model))->resolve());
            $report->save();

            $model->update(['mc_sent' => true]);
        }

        Log::info('MCSend done.');
    }
}

第二个:

namespace App\Jobs;

class MCCheckJob
{
    use Dispatchable, Queueable, MailerDriverMail;

    protected $dbConnection;

    public function __construct($dbConnection)
    {
        $this->dbConnection = $dbConnection;
    }

    public function handle(Config $config)
    {
        try {
            DB::connection($this->dbConnection)->getPdo();
            $config->{$this->dbConnection . '_status'} = true;
            $config->save();
            Log::info('MCCheck done.');
        } catch (PDOException $exception) {
            if ($this->dbConnection === 'mcdb') {
                Log::error('MCDB connection unavailable!');

                $config->mcdb_status = false;

                static::dispatch('rmcdb');
            } else {
                Log::error('RMCDB connection unavailable!');

                $config->rmcdb_status = false;
            }

            $config->save();

            Log::error('SQLSrv PDO Exception', ['error_code' => $exception->getErrorCode(), 'error_info' => $exception->getMessage()]);

            if(!empty($config->mailing_list_mc_reports)) {
                Mail::to($config->mailing_list_mc_reports)->send(new MCNoConnectionWarning($this->dbConnection));
            }
        }
    }
}

当我尝试使用链调度作业时,如下所示:MCSendJob::dispatch()->chain([new MCCheckJob('mcdb')])或者:MCSendJob::withChain([new MCCheckJob('mcdb')])->dispatch();我收到下一个错误:Call to undefined method App\Jobs\MCSendJob::chain()。我在Illuminate\Foundation\Bus\PendingDispatch中找到了这些方法。

无法弄清楚 - 问题出在哪里。

3 个答案:

答案 0 :(得分:0)

您需要在两个作业中使用Queueable特征

答案 1 :(得分:0)

我也遇到了同样的问题,这与Horizo​​n将脚本的早期版本有错误有关。

Horizo​​n快速重启,一切恢复正常。

答案 2 :(得分:0)

我遇到了同样的问题,通过重启主管解决了该问题:

service supervisord stop
service supervisord force-reload