Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding a proccess.id for workers.

  • Loading branch information...
commit 60e4778f84e66220c8bbca89bc4923a5cf8403be 1 parent 2322495
Joachim Kainz authored
View
8 examples/multi-worker.js
@@ -1,5 +1,4 @@
var http = require('http');
-var id = process.pid;
var loaded = 0;
/**
@@ -7,6 +6,7 @@ var loaded = 0;
* Failing to call the callback function will prevent the master from confinuing
*/
process.on('config', function(message, callback) {
+ console.log('Worker: Configured %s!', process.id);
callback();
});
@@ -18,14 +18,12 @@ process.on('message', function(message, callback) {
};
http.get(options, function(res) {
- callback(id, "status-code:", res.statusCode, "loaded", ++loaded);
+ callback(process.id, "status-code:", res.statusCode, "loaded", ++loaded);
}).on('error', function(e) {
callback("error:", e);
});
});
process.on('terminate', function(message, callback) {
- console.log("Worker: %s Loaded", id, ++loaded);
+ console.log("Worker: %s Loaded", process.id, ++loaded);
});
-
-console.log('Worker: Started %s!', id);
View
4 lib/backgrounder-launcher.js
@@ -116,6 +116,10 @@ function processMessage(message) {
var parsed = JSON.parse(message);
var callback = getCallback(parsed.id);
+ if ("config" === parsed.type) {
+ process.id = parsed.clientID;
+ }
+
emitter.emit(parsed.type, parsed.content, callback);
if ("terminate" === parsed.type) {
View
20 lib/backgrounder.js
@@ -217,16 +217,16 @@ function startChild(manager, module, config, idx, callback) {
child.process.stdin.on('close', function(code, signal) {
child.restart();
});
- if (config) {
- sendMessage(manager, idx, {
- "type": "config",
- "content": config
- }, function(){
- if (callback) {
- callback.apply(null, arguments);
- }
- });
- }
+ var _config = config || {};
+ sendMessage(manager, idx, {
+ "clientID" : idx,
+ "type": "config",
+ "content": _config
+ }, function(){
+ if (callback) {
+ callback.apply(null, arguments);
+ }
+ });
return child;
};
starter(callback);
Please sign in to comment.
Something went wrong with that request. Please try again.