From 5cbd28776c3eac25fad942e1d8fd1a9c3871406d Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 21 Mar 2024 10:33:19 +0900 Subject: [PATCH] =?UTF-8?q?JOB=E3=81=AE=E3=83=88=E3=83=A9=E3=83=B3?= =?UTF-8?q?=E3=82=B6=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit workジョブでシングルトンになっていたため2重のトランザクションが発生していた --- app/Jobs/BaseJob.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/Jobs/BaseJob.php b/app/Jobs/BaseJob.php index ace731a..65f9f01 100644 --- a/app/Jobs/BaseJob.php +++ b/app/Jobs/BaseJob.php @@ -8,26 +8,25 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; abstract class BaseJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - protected DBUtil $db; public function handle() { - $this->db = DBUtil::instance(); try { - $this->db->beginTransaction(); + DB::beginTransaction(); $this->logConfig(); $this->handleJob(); - $this->db->commit(); + DB::commit(); } catch (Exception $e) { - $this->db->rollBack(); + DB::rollBack(); throw $e; } }