2
私はlaravel v5.3.30で作業しています。私はguzzle要求を行い、データをシステムにインポートする複雑な仕事をしています。複数の作業者が複数回試行していると、データベースに3倍の挿入が加えられます。これは概観のようなものです:Laravelジョブが失敗したとマークされましたが、試行回数が多すぎますがジョブは成功しましたか?
<?php
namespace Uppdragshuset\AO\Tenant\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Uppdragshuset\AO\Tenant\Import\ImportHandler;
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個の行が表示されます。
例外を処理しているにもかかわらず、どのようにジョブが失敗しているのかわかりません。誰にも分かりますか?