0

我有两个工作,第一个需要在运行前调度第二个,我找到了工作链但不能让它工作,所有工作都是从盒子里设置的,所以理论上它应该可以工作。这是我的第一份工作:

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.

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

4

3 回答 3

3

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

于 2018-06-13T20:51:05.977 回答
1

我刚刚遇到了同样的问题,这与 Horizo​​n 将脚本的早期版本错误加载到内存中有关。

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

于 2019-10-02T12:33:14.003 回答
0

我有同样的问题,通过重新启动主管解决了:

service supervisord stop
service supervisord force-reload
于 2020-06-16T15:48:56.140 回答