Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReindexWorker resilient to ES connection issues #29908

Merged
merged 1 commit into from Feb 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions x-pack/plugins/upgrade_assistant/server/lib/reindexing/worker.ts
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