diff --git a/app/Jobs/ElasticSearchAliasInit.php b/app/Jobs/ElasticSearchAliasInit.php index 1bfc3c09..651448ad 100644 --- a/app/Jobs/ElasticSearchAliasInit.php +++ b/app/Jobs/ElasticSearchAliasInit.php @@ -5,6 +5,7 @@ use App\Http\Curl\HttpRequest; use App\WikiDb; use Illuminate\Foundation\Bus\Dispatchable; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Support\Facades\Log; class ElasticSearchAliasInit extends Job { @@ -24,6 +25,18 @@ public function __construct(int $wikiId, string $esHost, ?string $sharedPrefix = $this->sharedPrefix = $sharedPrefix ?? getenv('ELASTICSEARCH_SHARED_INDEX_PREFIX'); } + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array { + return [ + // Only allow one job per ES host to run at a time to avoid DoSing the ES cluster with alias updates + new WithoutOverlapping("elasticsearch-alias-init-{$this->esHost}"), + ]; + } + public function handle(HttpRequest $request) { Log::info(__METHOD__ . ": Updating Elasticsearch aliases for $this->wikiId");