Skip to content

Commit

Permalink
Merge pull request #11162 from notbakaneko/feature/remove-scores-sepa…
Browse files Browse the repository at this point in the history
…rate-connection

Prevent score removal jobs from overlapping
  • Loading branch information
nanaya authored Apr 27, 2024
2 parents 59fc729 + 257525a commit 0444f77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/Jobs/RemoveBeatmapsetBestScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
use App\Models\Score\Best\Model;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;

class RemoveBeatmapsetBestScores implements ShouldQueue
{
use Queueable, SerializesModels;
use InteractsWithQueue, Queueable, SerializesModels;

public $timeout = 36000;
public $beatmapset;
Expand Down Expand Up @@ -78,4 +80,9 @@ public function handle()
}
}
}

public function middleware(): array
{
return [new WithoutOverlapping((string) $this->beatmapset->getKey(), $this->timeout, $this->timeout)];
}
}
9 changes: 8 additions & 1 deletion app/Jobs/RemoveBeatmapsetSoloScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;

class RemoveBeatmapsetSoloScores implements ShouldQueue
{
use Queueable;
use InteractsWithQueue, Queueable;

public $timeout = 36000;

Expand Down Expand Up @@ -59,6 +61,11 @@ public function handle()
->chunkById(1000, fn ($scores) => $this->deleteScores($scores));
}

public function middleware(): array
{
return [new WithoutOverlapping((string) $this->beatmapsetId, $this->timeout, $this->timeout)];
}

private function deleteScores(Collection $scores): void
{
$ids = $scores->pluck('id')->all();
Expand Down
4 changes: 2 additions & 2 deletions config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/

'connections' => [

'sync' => [
'driver' => 'sync',
],
Expand All @@ -42,10 +41,11 @@
'retry_after' => 305,
],

// retry_after has to be longer than the job timeout; 5s added to allow time for workers to be killed.
'redis' => [
'driver' => 'redis',
'queue' => 'default',
'retry_after' => 305, // our longest job timeout is 5m, plus 5s to allow time for workers to be killed
'retry_after' => 305, // RegenerateBeatmapsetCover (300s),
],
],

Expand Down

0 comments on commit 0444f77

Please sign in to comment.