Skip to content
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

Support Worker Initialization Functions #113

Closed
wants to merge 2 commits into from

Conversation

joshuarubin
Copy link

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

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) {
  <initialization code goes here>
  if (error) {
    return callback(<error>)
  }
  // no error
  return callback(null);
}

When running the callback, one argument should be supplied. If the
<error> 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
Copy link
Contributor

tj commented Jun 27, 2011

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

@joshuarubin
Copy link
Author

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.

Signed-off-by: Joshua Rubin <joshua@rubixconsulting.com>
@tj
Copy link
Contributor

tj commented Jun 27, 2011

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
Copy link
Author

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

@tj
Copy link
Contributor

tj commented Jun 27, 2011

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

@joshuarubin joshuarubin closed this May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants