我正在尝试处理类中失败的作业。
执行此句柄()代码时发生错误。相应地,一个条目出现在failed_jobs表中。一切都很好。在这里执行一些代码,这会导致一个错误,从而导致作业失败。
public function failed()//****这里我想获得失败的job_id
代码
<?php
namespace AppJobs;
use
class ProcessResult implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
protected $id;
private $authUserId;
public function __construct($id, $authUserId)
{
$this->id = $id;
$this->authUserId = $authUserId;
}
/**
* Execute the job.
*
* @param $id
* @return void
*/
public function handle()
{
//Some code is executed here, which leads to an error and, accordingly, leads to the
failure of the job.
}
public function failed() //****HERE I want to get the job_id which is failed.
{
// Called when the job is failing...
Qprogress::where('queue_id', $this->job->getJobId())
->update(['qstatus' => 'job is failed' . $exception]);
}
AppServiceProvider
…
public function boot()
{
Queue::failing(function (JobFailed $event) {
// $event->connectionName
// $event->job
// $event->exception
Log::error('Oops, it did not work again...' . $event->job->getJobId ()); //Here is all is ok
});
非常感谢!
尝试这个失败的方法。
use Throwable;
public function failed(Throwable $exception)
{
Log::error('Failed job ID: ' . $this->job->getJobId());
}