Comparing version 3.3.0 to 3.3.1
@@ -0,5 +1,12 @@ | ||
v.3.3.1 | ||
======= | ||
- Fixed #714 | ||
[Changes](https://github.com/OptimalBits/bull/compare/v3.3.0...v3.3.1) | ||
v.3.3.0 | ||
======= | ||
- Added a method ```Queue##removeRepeatable``` to remove repeatable jobs. | ||
- | ||
- Now also emits drained as a global event. | ||
- Fixed #518, #624 | ||
@@ -6,0 +13,0 @@ [Changes](https://github.com/OptimalBits/bull/compare/v3.2.0...v3.3.0) |
@@ -0,53 +1,72 @@ | ||
'use strict'; | ||
var fork = require('child_process').fork; | ||
var path = require('path'); | ||
var pool = {}; | ||
var Promise = require('bluebird'); | ||
module.exports.retain = function(processFile){ | ||
return new Promise(function(resolve, reject) { | ||
var keys = Object.keys(pool); | ||
for(var i=0; i<keys.length; i++){ | ||
var child = pool[keys[i]]; | ||
if(!child.retained){ | ||
child.retained = true; | ||
return resolve(child.subprocess); | ||
module.exports = function ChildPool() { | ||
if(!(this instanceof ChildPool)){ | ||
return new ChildPool(); | ||
} | ||
var retained = {}; | ||
var free = []; | ||
this.retain = function(processFile){ | ||
return new Promise(function(resolve, reject) { | ||
var child = free.pop(); | ||
if(child){ | ||
return resolve(child); | ||
} | ||
} | ||
try{ | ||
var child = fork(path.join(__dirname, './master.js')); | ||
try{ | ||
var child = fork(path.join(__dirname, './master.js')); | ||
child.on('exit', function(code, signal){ | ||
console.error('Child process exited', child.pid, code, signal); | ||
delete pool[child.pid]; | ||
}); | ||
retained[child.id]; | ||
pool[child.pid] = { | ||
subprocess: child, | ||
retained: true | ||
}; | ||
child.on('exit', function(code, signal){ | ||
console.error('Child process exited', child.pid, code, signal); | ||
child.send({ | ||
cmd: 'init', | ||
value: processFile | ||
}, function() { | ||
resolve(child); | ||
}); | ||
}catch(err){ | ||
reject(err); | ||
// Remove exited child | ||
deleteChild(child); | ||
function deleteChild(child){ | ||
delete retained[child.pid]; | ||
var childIndex = free.indexOf(child); | ||
if (childIndex > -1) { | ||
free.splice(childIndex, 1); | ||
} | ||
} | ||
}); | ||
child.send({ | ||
cmd: 'init', | ||
value: processFile | ||
}, function() { | ||
resolve(child); | ||
}); | ||
} catch(err){ | ||
reject(err); | ||
} | ||
}); | ||
}; | ||
this.release = function(child){ | ||
delete retained[child.pid]; | ||
free.push(child); | ||
}; | ||
this.clean = function(){ | ||
var keys = Object.keys(retained); | ||
for(var i=0; i<keys.length; i++){ | ||
retained[keys[i]].kill(); | ||
} | ||
}); | ||
}; | ||
retained = {}; | ||
module.exports.release = function(child){; | ||
pool[child.pid].retained = false; | ||
for(var i=0; i<free.length; i++){ | ||
free[i].kill(); | ||
} | ||
free = []; | ||
}; | ||
}; | ||
module.exports.clean = function(){ | ||
var keys = Object.keys(pool); | ||
for(var i=0; i<keys.length; i++){ | ||
pool[keys[i]].subprocess.kill(); | ||
delete pool[keys[i]]; | ||
} | ||
}; |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
var Promise = require('bluebird'); | ||
var childPool = require('./child-pool'); | ||
module.exports = function(processFile){ | ||
module.exports = function(processFile, childPool){ | ||
return function process(job){ | ||
@@ -6,0 +7,0 @@ return childPool.retain(processFile).then(function(child){ |
@@ -489,3 +489,3 @@ /*eslint-env node */ | ||
}).finally(function(){ | ||
require('./process/child-pool').clean(); | ||
_this.childPool && _this.childPool.clean(); | ||
_this.closed = true; | ||
@@ -567,4 +567,5 @@ }); | ||
if(typeof handler === 'string'){ | ||
this.childPool = this.childPool || require('./process/child-pool')(); | ||
var sandbox = require('./process/sandbox'); | ||
this.handlers[name] = sandbox(handler).bind(this); | ||
this.handlers[name] = sandbox(handler, this.childPool).bind(this); | ||
} else { | ||
@@ -571,0 +572,0 @@ handler = handler.bind(this); |
{ | ||
"name": "bull", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"description": "Job manager", | ||
@@ -5,0 +5,0 @@ "main": "./lib/queue", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
464464
2670