我有两个工作,第一个需要在运行前调度第二个,我找到了工作链但不能让它工作,所有工作都是从盒子里设置的,所以理论上它应该可以工作。这是我的第一份工作:
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
.
无法弄清楚 - 问题出在哪里。