stop and start job polling when trying to claim jobs

also return claiming and execution Promise
This commit is contained in:
2016-04-28 16:25:45 -07:00
parent 379a8f096c
commit d3094375dd

View File

@@ -110,8 +110,10 @@ export default class Job extends events.EventEmitter {
}
_claimPendingJobs(jobs) {
this._stopJobPolling();
let claimed = false;
Bluebird.mapSeries(jobs, (job) => {
return Bluebird.mapSeries(jobs, (job) => {
if (claimed) return false;
return this._claimJob(job)
@@ -138,7 +140,8 @@ export default class Job extends events.EventEmitter {
const job = claimedJobs[0];
this.debug(`Beginning work on ${job._id}`);
return this._performJob(job);
});
})
.finally(() => this._startJobPolling());
}
_getPendingJobs() {