Skip to content

Commit 72d9cc3

Browse files
committed
Add $tries and releaseAfter() for ElasticSearchAliasInit job
Prevent the `WithoutOverlapping` middleware from causing jobs to fail due to `MaxAttemptsExceededException` Bug: T416158
1 parent 33423a4 commit 72d9cc3

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

app/Jobs/ElasticSearchAliasInit.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class ElasticSearchAliasInit extends Job {
1919

2020
public readonly string $sharedPrefix;
2121

22+
// Set $tries to 0 to enable unlimited retries for this job
23+
// https://laravel.com/docs/10.x/queues#max-attempts
24+
public int $tries = 0;
25+
2226
public function __construct(int $wikiId, string $esHost, ?string $sharedPrefix = null) {
2327
$this->wikiId = $wikiId;
2428
$this->esHost = $esHost;
@@ -32,8 +36,9 @@ public function __construct(int $wikiId, string $esHost, ?string $sharedPrefix =
3236
*/
3337
public function middleware(): array {
3438
return [
35-
// Only allow one job per ES host to run at a time to avoid DoSing the ES cluster with alias updates
36-
new WithoutOverlapping("elasticsearch-alias-init-{$this->esHost}"),
39+
// Only allow one job per ES host to run at a time to avoid DoSing the ES cluster with alias updates.
40+
// This job will only be retried after 15 seconds if another job for the same ES host is currently running.
41+
(new WithoutOverlapping("elasticsearch-alias-init-{$this->esHost}"))->releaseAfter(15),
3742
];
3843
}
3944

0 commit comments

Comments
 (0)