Skip to content

Commit

Permalink
fixes (#139)
Browse files Browse the repository at this point in the history
* extend cron

* lock unique jobs

* lock unique jobs
  • Loading branch information
andreiio authored Dec 2, 2024
1 parent c35522e commit be33bca
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 28 deletions.
52 changes: 50 additions & 2 deletions app/Enums/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'),
};
}
}
9 changes: 1 addition & 8 deletions app/Jobs/DeleteTemporaryTableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -53,6 +46,6 @@ public function handle(): void

public function uniqueId(): string
{
return "delete-temporary-table-data:{$this->model}";
return $this->model;
}
}
9 changes: 1 addition & 8 deletions app/Jobs/PersistTemporaryTableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -83,6 +76,6 @@ public function middleware(): array

public function uniqueId(): string
{
return "persist-temporary-table-data:{$this->model}";
return $this->model;
}
}
7 changes: 0 additions & 7 deletions app/Jobs/SchedulableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
26 changes: 25 additions & 1 deletion lang/ro/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit be33bca

Please sign in to comment.