LearnBoost / cluster

Node.JS multi-core server manager with plugins support.
http://learnboost.github.com/cluster
MIT License
2.29k stars 159 forks source link

Support Worker Initialization Functions #113

Closed joshuarubin closed 5 months ago

joshuarubin commented 13 years ago

Some workers may require an initialization sequence before they should connect to the socket.

In order to utilize this, simply add: .set('worker init', 'method name') to your cluster instance.

'method name' must be a method of the server that takes one callback argument as follows:

function server.worker_init(callback) {

if (error) { return callback(<error>) } // no error return callback(null); } When running the callback, one argument should be supplied. If the is "truthy", then the worker will consider it to have failed. If it is "falsy", then the worker will connect to the master. Signed-off-by: Joshua Rubin joshua@rubixconsulting.com
tj commented 13 years ago

what's the use-case for deferring the connection?

joshuarubin commented 13 years ago

I have some workers that need to fetch data from remote sites and/or do some disk loads before they will return acceptable results. I am using cluster for a very high volume web api and I am primarily concerned that the requests that come in from the time the worker is added, until initialized, will fail.

tj commented 13 years ago

I think I'd rather tackle this from a more abstract point of view, so that plugins could defer listening as well, then the logic you want to defer could just be a plugin, which happens to be specific to your app, but still just a plugin

joshuarubin commented 13 years ago

That would work well for me too. I am happy to help.

tj commented 13 years ago

actually never mind that, the api for exposing a plugin to the workers is pretty lame right now so that's not a great solution