From 03eca43bbffb8da579240df19c58e6361e61f6a0 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Thu, 28 Apr 2016 16:15:09 -0700 Subject: [PATCH] move job polling into another method, add stop method --- src/worker.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/worker.js b/src/worker.js index 6135223..34e2e3d 100644 --- a/src/worker.js +++ b/src/worker.js @@ -25,8 +25,8 @@ export default class Job extends events.EventEmitter { this.debug = (...msg) => debug(...msg, `id: ${this.id}`); - // this._pollForPendingJobs(); - this._checker = setInterval(() => this._pollForPendingJobs(), this.checkInterval); + this._checker = false; + this._startJobPolling(); } destroy() { @@ -109,8 +109,15 @@ export default class Job extends events.EventEmitter { return Promise.reject('mock es failure'); } - _pollForPendingJobs() { - this._getPendingJobs().then((jobs) => this._claimPendingJobs(jobs)); + _startJobPolling() { + this._checker = setInterval(() => { + this._getPendingJobs() + .then((jobs) => this._claimPendingJobs(jobs)); + } , this.checkInterval); + } + + _stopJobPolling() { + clearInterval(this._checker); } _claimPendingJobs(jobs) {