move job polling into another method, add stop method

This commit is contained in:
2016-04-28 16:15:09 -07:00
parent 1954141345
commit 03eca43bbf

View File

@@ -25,8 +25,8 @@ export default class Job extends events.EventEmitter {
this.debug = (...msg) => debug(...msg, `id: ${this.id}`); this.debug = (...msg) => debug(...msg, `id: ${this.id}`);
// this._pollForPendingJobs(); this._checker = false;
this._checker = setInterval(() => this._pollForPendingJobs(), this.checkInterval); this._startJobPolling();
} }
destroy() { destroy() {
@@ -109,8 +109,15 @@ export default class Job extends events.EventEmitter {
return Promise.reject('mock es failure'); return Promise.reject('mock es failure');
} }
_pollForPendingJobs() { _startJobPolling() {
this._getPendingJobs().then((jobs) => this._claimPendingJobs(jobs)); this._checker = setInterval(() => {
this._getPendingJobs()
.then((jobs) => this._claimPendingJobs(jobs));
} , this.checkInterval);
}
_stopJobPolling() {
clearInterval(this._checker);
} }
_claimPendingJobs(jobs) { _claimPendingJobs(jobs) {