stop and start job polling when trying to claim jobs
also return claiming and execution Promise
This commit is contained in:
@@ -110,8 +110,10 @@ export default class Job extends events.EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_claimPendingJobs(jobs) {
|
_claimPendingJobs(jobs) {
|
||||||
|
this._stopJobPolling();
|
||||||
let claimed = false;
|
let claimed = false;
|
||||||
Bluebird.mapSeries(jobs, (job) => {
|
|
||||||
|
return Bluebird.mapSeries(jobs, (job) => {
|
||||||
if (claimed) return false;
|
if (claimed) return false;
|
||||||
|
|
||||||
return this._claimJob(job)
|
return this._claimJob(job)
|
||||||
@@ -138,7 +140,8 @@ export default class Job extends events.EventEmitter {
|
|||||||
const job = claimedJobs[0];
|
const job = claimedJobs[0];
|
||||||
this.debug(`Beginning work on ${job._id}`);
|
this.debug(`Beginning work on ${job._id}`);
|
||||||
return this._performJob(job);
|
return this._performJob(job);
|
||||||
});
|
})
|
||||||
|
.finally(() => this._startJobPolling());
|
||||||
}
|
}
|
||||||
|
|
||||||
_getPendingJobs() {
|
_getPendingJobs() {
|
||||||
|
|||||||
Reference in New Issue
Block a user