From db89751ebf7ed3b89dbe561fff7c902f99acbd46 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 19 Dec 2022 16:31:23 +1100 Subject: [PATCH] Refactor for unique jobs --- app/Services/Bank/BankMatchingService.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Services/Bank/BankMatchingService.php b/app/Services/Bank/BankMatchingService.php index 00f1e1183c9f..963e669aef6c 100644 --- a/app/Services/Bank/BankMatchingService.php +++ b/app/Services/Bank/BankMatchingService.php @@ -21,6 +21,7 @@ use App\Models\Invoice; use App\Services\Bank\BankService; use App\Utils\Traits\GeneratesCounter; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; @@ -29,7 +30,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; -class BankMatchingService implements ShouldQueue +class BankMatchingService implements ShouldQueue, ShouldBeUnique { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -37,13 +38,10 @@ class BankMatchingService implements ShouldQueue protected $db; - protected $middleware_key; - public function __construct($company_id, $db) { $this->company_id = $company_id; $this->db = $db; - $this->middleware_key = "bank_match_rate:{$this->company_id}"; } public function handle() :void @@ -62,8 +60,14 @@ class BankMatchingService implements ShouldQueue } - public function middleware() + /** + * The unique ID of the job. + * + * @return string + */ + public function uniqueId() { - return [new WithoutOverlapping($this->middleware_key)]; + return (string)$this->company_id; } + }