-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pool): added optional setting for killing processes and not retaining them #1173
base: develop
Are you sure you want to change the base?
Changes from 1 commit
ac446e4
ff7774a
a8d3cd0
2b5bfdc
df11111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,7 +229,8 @@ var Queue = function Queue(name, url, opts) { | |
guardInterval: 5000, | ||
retryProcessDelay: 5000, | ||
drainDelay: 5, | ||
backoffStrategies: {} | ||
backoffStrategies: {}, | ||
keepProcesses: true | ||
}); | ||
|
||
this.settings.lockRenewTime = | ||
|
@@ -250,6 +251,13 @@ var Queue = function Queue(name, url, opts) { | |
this.processJob = this.processJob.bind(this); | ||
this.getJobFromId = Job.fromId.bind(null, this); | ||
|
||
// Check settings to see if processes will be kept after finishing processing, default set to true | ||
this.keepProcesses = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are setting a default value |
||
this.settings.keepProcesses !== undefined && | ||
this.settings.keepProcesses === false | ||
? false | ||
: true; | ||
|
||
var keys = {}; | ||
_.each( | ||
[ | ||
|
@@ -672,6 +680,10 @@ Queue.prototype.start = function(concurrency) { | |
}); | ||
}; | ||
|
||
Queue.prototype.setKeepProcesses = function(keepProcesses) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we need a setter for this setting, as with the other settings. |
||
this.keepProcesses = keepProcesses; | ||
}; | ||
|
||
Queue.prototype.setHandler = function(name, handler) { | ||
if (!handler) { | ||
throw new Error('Cannot set an undefined handler'); | ||
|
@@ -691,6 +703,7 @@ Queue.prototype.setHandler = function(name, handler) { | |
} | ||
|
||
this.childPool = this.childPool || require('./process/child-pool')(); | ||
this.childPool.setKeepProcesses(this.keepProcesses); | ||
|
||
var sandbox = require('./process/sandbox'); | ||
this.handlers[name] = sandbox(handler, this.childPool).bind(this); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,4 +142,20 @@ describe('Child pool', function() { | |
expect(children).to.include(child); | ||
}); | ||
}); | ||
|
||
it('should kill child after processing is finished and not retain it', function() { | ||
var processor = __dirname + '/fixtures/fixture_processor_bar.js'; | ||
var child; | ||
|
||
pool.setKeepProcesses(false); | ||
|
||
return pool.retain(processor).then(function(_child) { | ||
expect(_child).to.be.ok; | ||
child = _child; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this assignment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must have been from copy-paste, you are right no need for re-assigned the variable, could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated PR, removed the unnecessary reassignment |
||
pool.release(child); | ||
|
||
expect(pool.retained).to.be.empty; | ||
expect(pool.free[processor]).to.be.empty; | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking that it would be better to change the name to a more explanatory:
setReuseProcesses
or similar.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed the methods and variables in the latest PR