From be33bca833e0fd14235e6186b4bc1a9d1773b30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Mon, 2 Dec 2024 03:05:00 +0200 Subject: [PATCH] fixes (#139) * extend cron * lock unique jobs * lock unique jobs --- app/Enums/Cron.php | 52 ++++++++++++++++++- app/Jobs/DeleteTemporaryTableData.php | 9 +--- app/Jobs/PersistTemporaryTableData.php | 9 +--- app/Jobs/SchedulableJob.php | 7 --- .../Records/ImportAbroadRecordsJob.php | 8 ++- .../Records/ImportCountyRecordsJob.php | 8 ++- lang/ro/app.php | 26 +++++++++- 7 files changed, 91 insertions(+), 28 deletions(-) diff --git a/app/Enums/Cron.php b/app/Enums/Cron.php index 83d9393..db83d1e 100644 --- a/app/Enums/Cron.php +++ b/app/Enums/Cron.php @@ -18,16 +18,40 @@ enum Cron: string implements HasLabel case EVERY_3_MINUTES = '*/3 * * * *'; case EVERY_4_MINUTES = '*/4 * * * *'; case EVERY_5_MINUTES = '*/5 * * * *'; - case EVERY_10_MINUTES = '*/10 * * * *'; case EVERY_5_1_MINUTES = '1-59/5 * * * *'; case EVERY_5_2_MINUTES = '2-59/5 * * * *'; case EVERY_5_3_MINUTES = '3-59/5 * * * *'; case EVERY_5_4_MINUTES = '4-59/5 * * * *'; + case EVERY_10_MINUTES = '*/10 * * * *'; + case EVERY_10_1_MINUTES = '1-59/10 * * * *'; + case EVERY_10_2_MINUTES = '2-59/10 * * * *'; + case EVERY_10_3_MINUTES = '3-59/10 * * * *'; + case EVERY_10_4_MINUTES = '4-59/10 * * * *'; case EVERY_10_5_MINUTES = '5-59/10 * * * *'; case EVERY_10_6_MINUTES = '6-59/10 * * * *'; case EVERY_10_7_MINUTES = '7-59/10 * * * *'; case EVERY_10_8_MINUTES = '8-59/10 * * * *'; case EVERY_10_9_MINUTES = '9-59/10 * * * *'; + case EVERY_20_MINUTES = '*/20 * * * *'; + case EVERY_20_1_MINUTES = '1-59/20 * * * *'; + case EVERY_20_2_MINUTES = '2-59/20 * * * *'; + case EVERY_20_3_MINUTES = '3-59/20 * * * *'; + case EVERY_20_4_MINUTES = '4-59/20 * * * *'; + case EVERY_20_5_MINUTES = '5-59/20 * * * *'; + case EVERY_20_6_MINUTES = '6-59/20 * * * *'; + case EVERY_20_7_MINUTES = '7-59/20 * * * *'; + case EVERY_20_8_MINUTES = '8-59/20 * * * *'; + case EVERY_20_9_MINUTES = '9-59/20 * * * *'; + case EVERY_30_MINUTES = '*/30 * * * *'; + case EVERY_30_1_MINUTES = '1-59/30 * * * *'; + case EVERY_30_2_MINUTES = '2-59/30 * * * *'; + case EVERY_30_3_MINUTES = '3-59/30 * * * *'; + case EVERY_30_4_MINUTES = '4-59/30 * * * *'; + case EVERY_30_5_MINUTES = '5-59/30 * * * *'; + case EVERY_30_6_MINUTES = '6-59/30 * * * *'; + case EVERY_30_7_MINUTES = '7-59/30 * * * *'; + case EVERY_30_8_MINUTES = '8-59/30 * * * *'; + case EVERY_30_9_MINUTES = '9-59/30 * * * *'; public function getLabel(): ?string { @@ -37,16 +61,40 @@ public function getLabel(): ?string self::EVERY_3_MINUTES => __('app.cron.every_3_minutes'), self::EVERY_4_MINUTES => __('app.cron.every_4_minutes'), self::EVERY_5_MINUTES => __('app.cron.every_5_minutes'), - self::EVERY_10_MINUTES => __('app.cron.every_10_minutes'), self::EVERY_5_1_MINUTES => __('app.cron.every_5_1_minutes'), self::EVERY_5_2_MINUTES => __('app.cron.every_5_2_minutes'), self::EVERY_5_3_MINUTES => __('app.cron.every_5_3_minutes'), self::EVERY_5_4_MINUTES => __('app.cron.every_5_4_minutes'), + self::EVERY_10_MINUTES => __('app.cron.every_10_minutes'), + self::EVERY_10_1_MINUTES => __('app.cron.every_10_1_minutes'), + self::EVERY_10_2_MINUTES => __('app.cron.every_10_2_minutes'), + self::EVERY_10_3_MINUTES => __('app.cron.every_10_3_minutes'), + self::EVERY_10_4_MINUTES => __('app.cron.every_10_4_minutes'), self::EVERY_10_5_MINUTES => __('app.cron.every_10_5_minutes'), self::EVERY_10_6_MINUTES => __('app.cron.every_10_6_minutes'), self::EVERY_10_7_MINUTES => __('app.cron.every_10_7_minutes'), self::EVERY_10_8_MINUTES => __('app.cron.every_10_8_minutes'), self::EVERY_10_9_MINUTES => __('app.cron.every_10_9_minutes'), + self::EVERY_20_MINUTES => __('app.cron.every_20_minutes'), + self::EVERY_20_1_MINUTES => __('app.cron.every_20_1_minutes'), + self::EVERY_20_2_MINUTES => __('app.cron.every_20_2_minutes'), + self::EVERY_20_3_MINUTES => __('app.cron.every_20_3_minutes'), + self::EVERY_20_4_MINUTES => __('app.cron.every_20_4_minutes'), + self::EVERY_20_5_MINUTES => __('app.cron.every_20_5_minutes'), + self::EVERY_20_6_MINUTES => __('app.cron.every_20_6_minutes'), + self::EVERY_20_7_MINUTES => __('app.cron.every_20_7_minutes'), + self::EVERY_20_8_MINUTES => __('app.cron.every_20_8_minutes'), + self::EVERY_20_9_MINUTES => __('app.cron.every_20_9_minutes'), + self::EVERY_30_MINUTES => __('app.cron.every_30_minutes'), + self::EVERY_30_1_MINUTES => __('app.cron.every_30_1_minutes'), + self::EVERY_30_2_MINUTES => __('app.cron.every_30_2_minutes'), + self::EVERY_30_3_MINUTES => __('app.cron.every_30_3_minutes'), + self::EVERY_30_4_MINUTES => __('app.cron.every_30_4_minutes'), + self::EVERY_30_5_MINUTES => __('app.cron.every_30_5_minutes'), + self::EVERY_30_6_MINUTES => __('app.cron.every_30_6_minutes'), + self::EVERY_30_7_MINUTES => __('app.cron.every_30_7_minutes'), + self::EVERY_30_8_MINUTES => __('app.cron.every_30_8_minutes'), + self::EVERY_30_9_MINUTES => __('app.cron.every_30_9_minutes'), }; } } diff --git a/app/Jobs/DeleteTemporaryTableData.php b/app/Jobs/DeleteTemporaryTableData.php index 37e941b..6734bde 100644 --- a/app/Jobs/DeleteTemporaryTableData.php +++ b/app/Jobs/DeleteTemporaryTableData.php @@ -19,13 +19,6 @@ class DeleteTemporaryTableData implements ShouldQueue, ShouldBeUnique 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. */ @@ -53,6 +46,6 @@ public function handle(): void public function uniqueId(): string { - return "delete-temporary-table-data:{$this->model}"; + return $this->model; } } diff --git a/app/Jobs/PersistTemporaryTableData.php b/app/Jobs/PersistTemporaryTableData.php index 1e30879..cb24fe5 100644 --- a/app/Jobs/PersistTemporaryTableData.php +++ b/app/Jobs/PersistTemporaryTableData.php @@ -20,13 +20,6 @@ class PersistTemporaryTableData implements ShouldQueue, ShouldBeUnique 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. */ @@ -83,6 +76,6 @@ public function middleware(): array public function uniqueId(): string { - return "persist-temporary-table-data:{$this->model}"; + return $this->model; } } diff --git a/app/Jobs/SchedulableJob.php b/app/Jobs/SchedulableJob.php index 46d9049..325ca2d 100644 --- a/app/Jobs/SchedulableJob.php +++ b/app/Jobs/SchedulableJob.php @@ -30,13 +30,6 @@ public function __construct(ScheduledJob $scheduledJob) $this->scheduledJob = $scheduledJob; } - /** - * The number of seconds after which the job's unique lock will be released. - * - * @var int - */ - public $uniqueFor = 45; - abstract public function execute(): void; abstract public static function name(): string; diff --git a/app/Jobs/Y2024/M12/Parliament/Records/ImportAbroadRecordsJob.php b/app/Jobs/Y2024/M12/Parliament/Records/ImportAbroadRecordsJob.php index b8f2b7b..327bb1d 100644 --- a/app/Jobs/Y2024/M12/Parliament/Records/ImportAbroadRecordsJob.php +++ b/app/Jobs/Y2024/M12/Parliament/Records/ImportAbroadRecordsJob.php @@ -14,13 +14,14 @@ use App\Services\RecordService; use Illuminate\Bus\Batchable; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use League\Csv\Reader; -class ImportAbroadRecordsJob implements ShouldQueue +class ImportAbroadRecordsJob implements ShouldQueue, ShouldBeUnique { use Batchable; use Dispatchable; @@ -118,6 +119,11 @@ protected function getCountryId(string $name): string return $country->id; } + public function uniqueId(): string + { + return "{$this->scheduledJob->election_id}"; + } + /** * Get the tags that should be assigned to the job. * diff --git a/app/Jobs/Y2024/M12/Parliament/Records/ImportCountyRecordsJob.php b/app/Jobs/Y2024/M12/Parliament/Records/ImportCountyRecordsJob.php index b28b9ee..808c4b5 100644 --- a/app/Jobs/Y2024/M12/Parliament/Records/ImportCountyRecordsJob.php +++ b/app/Jobs/Y2024/M12/Parliament/Records/ImportCountyRecordsJob.php @@ -12,13 +12,14 @@ use App\Services\RecordService; use Illuminate\Bus\Batchable; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use League\Csv\Reader; -class ImportCountyRecordsJob implements ShouldQueue +class ImportCountyRecordsJob implements ShouldQueue, ShouldBeUnique { use Batchable; use Dispatchable; @@ -111,6 +112,11 @@ public function handle(): void Record::saveToTemporaryTable($records->all()); } + public function uniqueId(): string + { + return "{$this->scheduledJob->election_id}-{$this->county->code}"; + } + /** * Get the tags that should be assigned to the job. * diff --git a/lang/ro/app.php b/lang/ro/app.php index 72cdd4d..e73c508 100644 --- a/lang/ro/app.php +++ b/lang/ro/app.php @@ -174,16 +174,40 @@ 'every_3_minutes' => '3 minute', 'every_4_minutes' => '4 minute', 'every_5_minutes' => '5 minute', - 'every_10_minutes' => '10 minute', 'every_5_1_minutes' => '5+1 minute', 'every_5_2_minutes' => '5+2 minute', 'every_5_3_minutes' => '5+3 minute', 'every_5_4_minutes' => '5+4 minute', + 'every_10_minutes' => '10 minute', + 'every_10_1_minutes' => '10+1 minute', + 'every_10_2_minutes' => '10+2 minute', + 'every_10_3_minutes' => '10+3 minute', + 'every_10_4_minutes' => '10+4 minute', 'every_10_5_minutes' => '10+5 minute', 'every_10_6_minutes' => '10+6 minute', 'every_10_7_minutes' => '10+7 minute', 'every_10_8_minutes' => '10+8 minute', 'every_10_9_minutes' => '10+9 minute', + 'every_20_minutes' => '20 minute', + 'every_20_1_minutes' => '20+1 minute', + 'every_20_2_minutes' => '20+2 minute', + 'every_20_3_minutes' => '20+3 minute', + 'every_20_4_minutes' => '20+4 minute', + 'every_20_5_minutes' => '20+5 minute', + 'every_20_6_minutes' => '20+6 minute', + 'every_20_7_minutes' => '20+7 minute', + 'every_20_8_minutes' => '20+8 minute', + 'every_20_9_minutes' => '20+9 minute', + 'every_30_minutes' => '30 minute', + 'every_30_1_minutes' => '30+1 minute', + 'every_30_2_minutes' => '30+2 minute', + 'every_30_3_minutes' => '30+3 minute', + 'every_30_4_minutes' => '30+4 minute', + 'every_30_5_minutes' => '30+5 minute', + 'every_30_6_minutes' => '30+6 minute', + 'every_30_7_minutes' => '30+7 minute', + 'every_30_8_minutes' => '30+8 minute', + 'every_30_9_minutes' => '30+9 minute', ], 'area' => [