Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes PriorityQueue Events and Local Worker Pause/Resume #341

Merged
merged 2 commits into from
Nov 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions lib/priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,22 @@ var PriorityQueue = module.exports = function(name, redisPort, redisHost, redisO
this.queues[PriorityQueue.priorities[key]] = queue;
}

Promise.map(this.queues, function(queue) {
return new Promise(function(resolve, reject) {
queue.once('ready', resolve);
});
}).then(_this.emit.bind(_this, 'ready'))

this.queues.forEach(function(queue) {
queue.on('error', _this.emit.bind(_this, 'error'));
})

this.queues.forEach(function(queue) {
queue.on('progress', _this.emit.bind(_this, 'progress'));
})

this.queues.forEach(function(queue) {
queue.on('completed', _this.emit.bind(_this, 'completed'));
var groupEvents = ['ready', 'paused', 'resumed']
groupEvents.forEach(function(event) {
Promise.map(_this.queues, function(queue) {
return new Promise(function(resolve, reject) {
queue.once(event, resolve);
});
}).then(_this.emit.bind(_this, event))
})

this.queues.forEach(function(queue) {
queue.on('failed', _this.emit.bind(_this, 'failed'));
var singleEvents = ['error', 'active', 'stalled', 'progress', 'completed', 'failed', 'cleaned']
singleEvents.forEach(function(event) {
_this.queues.forEach(function(queue) {
queue.on(event, _this.emit.bind(_this, event))
})
})


this.strategy = Strategy.exponential;
}

Expand Down Expand Up @@ -164,21 +157,21 @@ PriorityQueue.prototype.empty = function() {
});
}

PriorityQueue.prototype.pause = function() {
PriorityQueue.prototype.pause = function(localOnly) {
var _this = this;

_this.paused = Promise.map(this.queues, function(queue) {
return queue.pause();
return queue.pause(localOnly || false);
}).then(_this.emit.bind(_this, 'paused'));

return _this.paused;
}

PriorityQueue.prototype.resume = function() {
PriorityQueue.prototype.resume = function(localOnly) {
var _this = this;
_this.paused = false;
return Promise.map(this.queues, function(queue) {
return queue.resume();
return queue.resume(localOnly || false);
}).then(_this.emit.bind(_this, 'resumed')).then(function() {
if (_this.handler) {
_this.run();
Expand Down