Skip to content

Commit

Permalink
now sending exist status.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Kainz committed Oct 11, 2011
1 parent 4a5425b commit 0ce4dee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 16 additions & 0 deletions lib/backgrounder-launcher.js
Expand Up @@ -190,6 +190,22 @@ process.send = function(message, id) {
var json = JSON.stringify(msg); var json = JSON.stringify(msg);
process.stdout.write(json + '\n'); process.stdout.write(json + '\n');
}; };
//
// Send a message to the parent that exist was called
//
var process_exit = process.exit;
process.exit = function(code) {
var msg = {
"type": "terminating",
"code" : code
};

var json = JSON.stringify(msg);
process.stdout.write(json + '\n');
process.nextTick(function(){
process_exit(code);
});
}
console.info = console.log; console.info = console.log;


function getTitle(worker) { function getTitle(worker) {
Expand Down
12 changes: 5 additions & 7 deletions lib/backgrounder.js
Expand Up @@ -9,15 +9,15 @@ function getAvailableChild(manager) {
for(var idx = manager.lastUsed+1; idx < manager.children.length; idx++) { for(var idx = manager.lastUsed+1; idx < manager.children.length; idx++) {
var child = manager.children[idx]; var child = manager.children[idx];


if (!child.pending) { if (child && !child.pending) {
return manager.lastUsed = idx; return manager.lastUsed = idx;
} }
} }


for(var idx = .0; idx < manager.children.length; idx++) { for(var idx = .0; idx < manager.children.length; idx++) {
var child = manager.children[idx]; var child = manager.children[idx];


if (!child.pending) { if (child && !child.pending) {
return manager.lastUsed = idx; return manager.lastUsed = idx;
} }
} }
Expand Down Expand Up @@ -49,7 +49,6 @@ function emitMessage(child, message) {
// Send a message to the client (do the actual work: stringify, write to stdin, increment the pending counter) // Send a message to the client (do the actual work: stringify, write to stdin, increment the pending counter)
// //
function sendMessage(manager, id, message, callback) { function sendMessage(manager, id, message, callback) {
console.log("send message %s", id);
var child = manager.children[id]; var child = manager.children[id];


if (!child) { if (!child) {
Expand Down Expand Up @@ -136,6 +135,9 @@ function processMessage(child, message) {
else if (message.type === 'completed') { else if (message.type === 'completed') {
processCompleted(child, message); processCompleted(child, message);
} }
else if (message.type === 'terminating') {
child.restart();
}
else { else {
console.error("unexpected message %s", util.inspect(message)); console.error("unexpected message %s", util.inspect(message));
} }
Expand Down Expand Up @@ -202,7 +204,6 @@ function startChild(manager, module, config, idx, callback) {
return; return;
} }
if (manager.children[idx] && manager.children[idx] != this) { if (manager.children[idx] && manager.children[idx] != this) {
console.log("already restarted");
return; return;
} }
} }
Expand All @@ -212,11 +213,8 @@ function startChild(manager, module, config, idx, callback) {
delete manager.children[idx]; delete manager.children[idx];
} }
}; };
console.log("restarted %s", idx);
manager.children[idx] = child; manager.children[idx] = child;
child.process.stdin.on('close', function(code, signal) { child.process.stdin.on('close', function(code, signal) {
delete child.process;
console.log("stdin %s closed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", idx);
child.restart(); child.restart();
}); });
if (config) { if (config) {
Expand Down

0 comments on commit 0ce4dee

Please sign in to comment.