Skip to content

Commit

Permalink
added isReady and throw initialization errors
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Mar 30, 2017
1 parent ab672fe commit 674fce5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ var Queue = function Queue(name, redisPort, redisHost, redisOptions){

// emit ready when redis connections ready
var initializers = [this.client, this.bclient, this.eclient].map(function (client) {
return new Promise(function(resolve) {
return new Promise(function(resolve, reject) {
client.once('ready', resolve);
client.once('error', reject);
});
});

this._initializing = Promise.all(initializers)
.then(function(){
this._initializing = Promise.all(initializers).then(function(){
return Promise.join(
_this.eclient.subscribe(_this.toKey('delayed')),
_this.eclient.subscribe(_this.toKey('paused'))
Expand Down Expand Up @@ -274,6 +274,13 @@ var Queue = function Queue(name, redisPort, redisHost, redisOptions){

util.inherits(Queue, Disturbed);

Queue.prototype.isReady = function(){
var _this = this;
return this._initializing.then(function(){
return _this;
});
}

Queue.prototype.getJobMoveCount = function(){
return this.bclient.commandQueue.length;
};
Expand Down Expand Up @@ -786,7 +793,6 @@ Queue.prototype.moveJob = function(src, dst, opts) {
var args = arguments;
var _this = this;
var move;

if(opts && opts.block === false){
if(!this.closing){
move = this.bclient.rpoplpush(this.toKey(src), this.toKey(dst));
Expand Down

0 comments on commit 674fce5

Please sign in to comment.