diff --git a/app/Jobs/DeleteTemporaryTableData.php b/app/Jobs/DeleteTemporaryTableData.php index 7aceebb..37e941b 100644 --- a/app/Jobs/DeleteTemporaryTableData.php +++ b/app/Jobs/DeleteTemporaryTableData.php @@ -6,11 +6,12 @@ use App\Contracts\TemporaryTable; use Exception; +use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\DB; -class DeleteTemporaryTableData implements ShouldQueue +class DeleteTemporaryTableData implements ShouldQueue, ShouldBeUnique { use Queueable; @@ -18,6 +19,13 @@ class DeleteTemporaryTableData implements ShouldQueue public int $electionId; + /** + * The number of seconds after which the job's unique lock will be released. + * + * @var int + */ + public $uniqueFor = 45; + /** * Create a new job instance. */ @@ -42,4 +50,9 @@ public function handle(): void ->where('election_id', $this->electionId) ->delete(); } + + public function uniqueId(): string + { + return "delete-temporary-table-data:{$this->model}"; + } } diff --git a/app/Jobs/PersistTemporaryTableData.php b/app/Jobs/PersistTemporaryTableData.php index 5544cbc..1e30879 100644 --- a/app/Jobs/PersistTemporaryTableData.php +++ b/app/Jobs/PersistTemporaryTableData.php @@ -7,11 +7,12 @@ use App\Contracts\TemporaryTable; use App\Jobs\Middleware\RateLimitSchedulableJobMiddleware; use Exception; +use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\DB; -class PersistTemporaryTableData implements ShouldQueue +class PersistTemporaryTableData implements ShouldQueue, ShouldBeUnique { use Queueable; @@ -19,6 +20,13 @@ class PersistTemporaryTableData implements ShouldQueue public ?int $electionId; + /** + * The number of seconds after which the job's unique lock will be released. + * + * @var int + */ + public $uniqueFor = 45; + /** * Create a new job instance. */ @@ -72,4 +80,9 @@ public function middleware(): array new RateLimitSchedulableJobMiddleware('persist-temporary-table-data'), ]; } + + public function uniqueId(): string + { + return "persist-temporary-table-data:{$this->model}"; + } }