Skip to content

Commit

Permalink
Make ReindexWorker resilient to ES connection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Feb 2, 2019
1 parent 6888cd4 commit 454a80c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions x-pack/plugins/upgrade_assistant/server/lib/reindexing/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class ReindexWorker {
private static workerSingleton?: ReindexWorker;
private continuePolling: boolean = false;
private updateOperationLoopRunning: boolean = false;
private timeout?: NodeJS.Timeout;
private inProgressOps: ReindexSavedObject[] = [];
private readonly reindexService: ReindexService;

Expand Down Expand Up @@ -73,6 +74,10 @@ export class ReindexWorker {
*/
public stop = () => {
this.log(['debug', ...LOG_TAGS], `Stopping worker...`);
if (this.timeout) {
clearTimeout(this.timeout);
}

this.updateOperationLoopRunning = false;
this.continuePolling = false;
};
Expand Down Expand Up @@ -114,12 +119,17 @@ export class ReindexWorker {
await this.refresh();

if (this.continuePolling) {
setTimeout(this.pollForOperations, POLL_INTERVAL);
this.timeout = setTimeout(this.pollForOperations, POLL_INTERVAL);
}
};

private refresh = async () => {
this.inProgressOps = await this.reindexService.findAllByStatus(ReindexStatus.inProgress);
try {
this.inProgressOps = await this.reindexService.findAllByStatus(ReindexStatus.inProgress);
} catch (e) {
this.log(['debug', ...LOG_TAGS], `Could not fetch riendex operations from Elasticsearch`);
this.inProgressOps = [];
}

// If there are operations in progress and we're not already updating operations, kick off the update loop
if (!this.updateOperationLoopRunning) {
Expand Down

0 comments on commit 454a80c

Please sign in to comment.