Laravel 5.5 作业链:调用未定义的方法 ::chain()
Laravel 5.5 Job Chaining: Call to undefined method ::chain()
我有两个工作,第一个需要在 运行 之前派发第二个,我找到了工作链但无法使其工作,所有工作都是从盒子中设置的,所以理论上它应该可以工作.
这是我的第一份工作:
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
.
中找到了那些方法
想不通 - 问题出在哪里。
您需要在两个作业中使用 Queueable 特性
我刚遇到同样的问题,这与 Horizon 加载到内存中的错误早期版本脚本有关。
Horizon 快速重启,一切正常。
我遇到了同样的问题,通过重启 supervisor 解决了:
service supervisord stop
service supervisord force-reload
我有两个工作,第一个需要在 运行 之前派发第二个,我找到了工作链但无法使其工作,所有工作都是从盒子中设置的,所以理论上它应该可以工作. 这是我的第一份工作:
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
.
想不通 - 问题出在哪里。
您需要在两个作业中使用 Queueable 特性
我刚遇到同样的问题,这与 Horizon 加载到内存中的错误早期版本脚本有关。
Horizon 快速重启,一切正常。
我遇到了同样的问题,通过重启 supervisor 解决了:
service supervisord stop
service supervisord force-reload