move poller state into this._poller
This commit is contained in:
@@ -34,14 +34,17 @@ export default class Worker extends events.EventEmitter {
|
|||||||
|
|
||||||
this.debug = (...msg) => debug(...msg, `id: ${this.id}`);
|
this.debug = (...msg) => debug(...msg, `id: ${this.id}`);
|
||||||
|
|
||||||
this._checker = false;
|
this._poller = {
|
||||||
this._running = true;
|
timer: false,
|
||||||
|
enabled: true,
|
||||||
|
};
|
||||||
|
|
||||||
this.debug(`Created worker for job type ${this.jobtype}`);
|
this.debug(`Created worker for job type ${this.jobtype}`);
|
||||||
this._startJobPolling();
|
this._startJobPolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this._running = false;
|
this._poller.enabled = false;
|
||||||
this._stopJobPolling();
|
this._stopJobPolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,18 +250,17 @@ export default class Worker extends events.EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_startJobPolling() {
|
_startJobPolling() {
|
||||||
if (!this._running) {
|
if (!this._poller.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._checker = setInterval(() => {
|
this._poller.timer = setInterval(() => {
|
||||||
this._getPendingJobs()
|
this._getPendingJobs().then((jobs) => this._claimPendingJobs(jobs));
|
||||||
.then((jobs) => this._claimPendingJobs(jobs));
|
|
||||||
} , this.checkInterval);
|
} , this.checkInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
_stopJobPolling() {
|
_stopJobPolling() {
|
||||||
clearInterval(this._checker);
|
clearInterval(this._poller.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
_claimPendingJobs(jobs) {
|
_claimPendingJobs(jobs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user