Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/Jobs/ElasticSearchAliasInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also add $tries and $backoff class properties to this job so that any failed jobs are retried after a period of time. https://laravel.com/docs/12.x/queues#dealing-with-failed-jobs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the worst idea. I think perhaps we could also add this with a follow-up if, when we run it, we see any failure. For now I'd leave it be

Expand All @@ -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<int, object>
*/
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}"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: nice, and good to do it per cluster rather than globally

];
}

public function handle(HttpRequest $request) {
Log::info(__METHOD__ . ": Updating Elasticsearch aliases for $this->wikiId");

Expand Down
Loading