From a2c71afa73cd6427af48da266ce35e85d2a68370 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 1 Oct 2024 11:48:17 +1000 Subject: [PATCH] Updates to Jobs so they are all queable, and overlapping is consistent --- app/Jobs/CatalogDelete.php | 17 ++++++++++++++++- app/Jobs/CatalogMove.php | 10 +++++++++- app/Jobs/CatalogScan.php | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/Jobs/CatalogDelete.php b/app/Jobs/CatalogDelete.php index a1bd5e2..542b1f9 100644 --- a/app/Jobs/CatalogDelete.php +++ b/app/Jobs/CatalogDelete.php @@ -2,6 +2,8 @@ namespace App\Jobs; +use Illuminate\Foundation\Queue\Queueable; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Support\Facades\Log; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; @@ -11,7 +13,7 @@ use App\Models\Abstracted\Catalog; class CatalogDelete implements ShouldQueue { - use InteractsWithQueue,SerializesModels; + use InteractsWithQueue,Queueable,SerializesModels; // Our object private Catalog $o; @@ -26,6 +28,19 @@ class CatalogDelete implements ShouldQueue $this->o = $o; } + public function middleware(): array + { + return [new WithoutOverlapping($this->uniqueId())]; + } + + /** + * Get the unique ID for the job. + */ + public function uniqueId(): string + { + return $this->o::config.'|'.$this->o->id; + } + /** * Execute the job. * diff --git a/app/Jobs/CatalogMove.php b/app/Jobs/CatalogMove.php index efa95ba..d530e6f 100644 --- a/app/Jobs/CatalogMove.php +++ b/app/Jobs/CatalogMove.php @@ -32,7 +32,15 @@ class CatalogMove implements ShouldQueue,ShouldBeUnique public function middleware(): array { - return [new WithoutOverlapping($this->o::config.'|'.$this->o->id)]; + return [new WithoutOverlapping($this->uniqueId())]; + } + + /** + * Get the unique ID for the job. + */ + public function uniqueId(): string + { + return $this->o::config.'|'.$this->o->id; } /** diff --git a/app/Jobs/CatalogScan.php b/app/Jobs/CatalogScan.php index e322e5a..1e1efd5 100644 --- a/app/Jobs/CatalogScan.php +++ b/app/Jobs/CatalogScan.php @@ -12,7 +12,7 @@ use Illuminate\Support\Facades\Log; use App\Models\Abstracted\Catalog; -class CatalogScan implements ShouldQueue, ShouldBeUnique +class CatalogScan implements ShouldQueue,ShouldBeUnique { use InteractsWithQueue,Queueable,SerializesModels;