Comparing version 0.1.2 to 0.1.3
@@ -26,3 +26,3 @@ "use strict"; | ||
for(var i=0; i<maxPriority; i++){ | ||
queues.push(new Queue(name+)) | ||
queues.push(Queue(name+':prio:'+i)); | ||
} | ||
@@ -29,0 +29,0 @@ } |
@@ -133,3 +133,6 @@ "use strict"; | ||
var defer = when.defer(); | ||
var | ||
defer = when.defer(), | ||
_this = this; | ||
this.paused = defer.promise; | ||
@@ -139,8 +142,9 @@ | ||
this.once('completed', function(){ | ||
_this.emit('paused'); | ||
defer.resolve(); | ||
}); | ||
}else{ | ||
this.emit('paused'); | ||
defer.resolve(); | ||
} | ||
return this.paused; | ||
@@ -153,3 +157,7 @@ } | ||
return this.paused.then(function(){ | ||
_this.run(); | ||
_this.paused = null; | ||
_this.emit('resumed'); | ||
if(_this.handler){ | ||
_this.run(); | ||
} | ||
}); | ||
@@ -193,2 +201,3 @@ } | ||
var _this = this; | ||
return this.getNextJob().then(function(job){ | ||
@@ -195,0 +204,0 @@ return _this.processJob(job); |
{ | ||
"name": "bull", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Job manager", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -78,3 +78,13 @@ Bull Job Manager | ||
queue.createJob('image transcode', {image: 'http://example.com/image1.tiff'}); | ||
A queue can be paused and resumed: | ||
queue.pause().then(function(){ | ||
// queue is paused now | ||
}); | ||
queue.resume().then(function(){ | ||
// queue is resumed now | ||
}) | ||
A queue emits also some useful events: | ||
@@ -91,4 +101,9 @@ | ||
}) | ||
.on('paused', function(){ | ||
// The queue has been paused | ||
}) | ||
.on('progress', function(job, progress){ | ||
// The queue has been resumed | ||
}) | ||
Queues are cheap, so if you need many of them just create new ones with different | ||
@@ -95,0 +110,0 @@ names: |
@@ -136,4 +136,4 @@ var Job = require('../lib/job'); | ||
it('add a job to a paused queue', function(done){ | ||
var ispaused = false; | ||
it('add jobs to a paused queue', function(done){ | ||
var ispaused = false, counter = 2; | ||
@@ -144,19 +144,54 @@ queue.process(function(job, jobDone){ | ||
jobDone(); | ||
done(); | ||
counter--; | ||
if(counter === 0) done(); | ||
}); | ||
queue.pause(); | ||
ispaused = true; | ||
queue.add({foo: 'paused'}); | ||
queue.add({foo: 'paused'}); | ||
setTimeout(function(){ | ||
console.log("papagayo") | ||
ispaused = false; | ||
queue.resume(); | ||
}, 1000); // We hope that this was enough to trigger a process if | ||
}, 100); // We hope that this was enough to trigger a process if | ||
// we were not paused. | ||
}); | ||
it('paused a running queue', function(done){ | ||
var ispaused = false, isresumed = true, first = true; | ||
queue.process(function(job, jobDone){ | ||
expect(ispaused).to.be(false); | ||
expect(job.data.foo).to.be.equal('paused'); | ||
jobDone(); | ||
if(first){ | ||
first = false; | ||
queue.pause(); | ||
ispaused = true; | ||
}else{ | ||
expect(isresumed).to.be(true); | ||
done(); | ||
} | ||
}); | ||
queue.add({foo: 'paused'}); | ||
queue.add({foo: 'paused'}); | ||
queue.on('paused', function(){ | ||
setTimeout(function(){ | ||
ispaused = false; | ||
queue.resume(); | ||
}, 100); // We hope that this was enough to trigger a process if | ||
}); | ||
queue.on('resumed', function(){ | ||
isresumed = true; | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31081
812
248