mirror of
https://github.com/harish2704/node-job-manager.git
synced 2026-09-10 13:11:08 +00:00
Set minimum concurreny,
fix: call stop() if all tesks are processed
This commit is contained in:
+10
-8
@@ -40,15 +40,17 @@ JobManager.prototype.updateState = function(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
JobManager.prototype.setConcurrency = function( newVal ){
|
JobManager.prototype.setConcurrency = function( newVal ){
|
||||||
if( newVal > this.tmpPoolLen ){
|
if( newVal > 1){
|
||||||
var tmpPool = this.tmpPool;
|
if( newVal > this.tmpPoolLen ){
|
||||||
var additionalPoolBlocks = Math.ceil( ( newVal - this.tmpPoolLen )/this.workers.length ), i;
|
var tmpPool = this.tmpPool;
|
||||||
for( i=0; i < additionalPoolBlocks; i++){
|
var additionalPoolBlocks = Math.ceil( ( newVal - this.tmpPoolLen )/this.workers.length ), i;
|
||||||
tmpPool = tmpPool.concat( this.workers );
|
for( i=0; i < additionalPoolBlocks; i++){
|
||||||
|
tmpPool = tmpPool.concat( this.workers );
|
||||||
|
}
|
||||||
|
this.tmpPoolLen += additionalPoolBlocks * this.workers.length ;
|
||||||
}
|
}
|
||||||
this.tmpPoolLen += additionalPoolBlocks * this.workers.length ;
|
this.concurrency = newVal;
|
||||||
}
|
}
|
||||||
this.concurrency = newVal;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -73,7 +75,7 @@ JobManager.prototype.$doWork_ = function( cb ){
|
|||||||
var self = this;
|
var self = this;
|
||||||
var task = self.tasks.splice(0, 1)[0];
|
var task = self.tasks.splice(0, 1)[0];
|
||||||
if( task == undefined ){
|
if( task == undefined ){
|
||||||
if( this.onStopped ){ this.onStopped(); }
|
this.stop();
|
||||||
}
|
}
|
||||||
var worker = self.getFromPool();
|
var worker = self.getFromPool();
|
||||||
this.work( task, worker, function(err){
|
this.work( task, worker, function(err){
|
||||||
|
|||||||
Reference in New Issue
Block a user