Laravel作业标记为失败,异常说尝试次数太多,但工作成功?



我正在使用 laravel v5.3.30,我有复杂的工作,那就是执行 guzzle 请求并将数据导入系统。如果我多次尝试多个工作线程,我会在我的数据库中插入两次,甚至三次。以下是作业概述:

<?php
namespace UppdragshusetAOTenantJobs;
use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateQueueInteractsWithQueue;
use IlluminateQueueSerializesModels;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesLog;
use UppdragshusetAOTenantImportImportHandler;
class ImportPatentCreateCaseJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $number;
protected $import;
protected $workflow_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($number, $import, $workflow_id)
{
$this->number = $number;
$this->import = $import;
$this->workflow_id = $workflow_id;
$this->onQueue('import');
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$importHandler = new ImportHandler();
try {
DB::beginTransaction();
$patent = $importHandler->checkIfPatentExists($this->number['number']);
if( ! $patent){
$patent = $importHandler->handlePatentData($this->number);
}
if( ! $importHandler->checkIfCaseExists($patent->id, $this->workflow_id)){
$task_id = $importHandler->prepareWorkflowAndGetTaskId($this->workflow_id);
$importHandler->createCase($this->workflow_id, $task_id, $patent->id);
}
$this->import->update([
'status' => 'COMPLETED'
]);
DB::commit();
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
DB::rollBack();
$this->import->update([
'status' => 'FAILED'
]);
}
$importHandler->markBatchAsCompleted($this->import);
}
}

我正在检查数据是否已经存在,如果存在,则不应再次导入。我什至将整个代码包装在 try catch 语句中,因此即使某些内容失败,它也会记录它并且作业会运行良好。

当我尝试使用tries=1时,创建了 55 个作业,其中 7 个失败,但我的失败作业表显示其中有 30 行。

所以我不明白即使我正在处理异常,工作是如何失败的。有人知道吗?

将作业推送到没有工作人员的队列并手动处理此作业

相关内容

最新更新