From bb898e26c267eea552a7fb6f56aadf4cfab6880e Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 23 May 2017 20:16:05 -0700 Subject: [PATCH] add 20x delay when search results in an error --- src/worker.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/worker.js b/src/worker.js index 7be854a..4cee588 100644 --- a/src/worker.js +++ b/src/worker.js @@ -256,7 +256,8 @@ export default class Worker extends events.EventEmitter { } this._poller.timer = setTimeout(() => { - this._getPendingJobs().then((jobs) => { + this._getPendingJobs() + .then((jobs) => { if (!this._poller.running) return; const foundJobs = (!jobs || jobs.length === 0); @@ -266,6 +267,16 @@ export default class Worker extends events.EventEmitter { this._poller.running = false; this._startJobPolling(); }); + }, () => { + // if the search failed for some reason, back off the polling + // we assume errors came from a busy cluster + // TODO: check what error actually happened + const multiplier = 20; + + setTimeout(() => { + this._poller.running = false; + this._startJobPolling(); + }, this.checkInterval * multiplier); }); } , this.checkInterval);