Comparing version
{ | ||
"name": "qjobs", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "qjobs is a simple and stupid queue job manager for nodejs", | ||
@@ -5,0 +5,0 @@ "main": "qjobs.js", |
@@ -181,10 +181,12 @@ var util = require('util'); | ||
clearInterval(this.pausedId); | ||
self.emit('unpause'); | ||
this.run(); | ||
} | ||
if (this.paused && !this.pausedId) { | ||
this.lastPause = Date.now(); | ||
self.lastPause = Date.now(); | ||
this.pausedId = setInterval(function() { | ||
var since = Date.now() - lastPause; | ||
self.emit('inPause',since); | ||
var since = Date.now() - self.lastPause; | ||
self.emit('pause',since); | ||
},1000); | ||
return; | ||
} | ||
@@ -191,0 +193,0 @@ } |
@@ -36,3 +36,5 @@ [](http://travis-ci.org/franck34/qjobs) | ||
``` | ||
// My non blocking main job | ||
var qjobs = new require('./qjobs'); | ||
// My non blocking main job | ||
var myjob = function(args,next) { | ||
@@ -45,34 +47,31 @@ setTimeout(function() { | ||
// qjobs stuff | ||
var q = new qjobs({maxConcurrency:10}); | ||
var myQueueJobs = new require('qjobs'); | ||
// Let's add 30 job to the queue | ||
for (var i = 0; i<30; i++) { | ||
myQueueJobs.add(myjob,[i,'test '+i]); | ||
q.add(myjob,[i,'test '+i]); | ||
} | ||
// Initialize all events | ||
myQueueJobs.on('start',function() { | ||
q.on('start',function() { | ||
console.log('Starting ...'); | ||
}); | ||
myQueueJobs.on('end',function() { | ||
q.on('end',function() { | ||
console.log('... All jobs done'); | ||
}); | ||
myQueueJobs.on('jobStart',function(args) { | ||
q.on('jobStart',function(args) { | ||
console.log('jobStart',args); | ||
}); | ||
myQueueJobs.on('jobEnd',function(args) { | ||
q.on('jobEnd',function(args) { | ||
console.log('jobend',args); | ||
// If i'm jobId 10, then make a pause of 5 sec | ||
if (args._jobId == 10) { | ||
myQueueJobs.pause(true); | ||
q.pause(true); | ||
setTimeout(function() { | ||
myQueueJobs.pause(false); | ||
q.pause(false); | ||
},5000); | ||
@@ -82,11 +81,12 @@ } | ||
// I want to know if queue is in pause every sec | ||
myQueueJobs.on('inPause',function(since) { | ||
q.on('pause',function(since) { | ||
console.log('in pause since '+since+' milliseconds'); | ||
}); | ||
q.on('unpause',function() { | ||
console.log('pause end, continu ..'); | ||
}); | ||
// JOBS !! leeeeeeeeeet's staaaaaaaart ! | ||
myQueueJobs.run(); | ||
q.run(); | ||
``` | ||
14325
13.15%10
11.11%416
19.54%