Skip to content
Browse files

now sending exist status.

  • Loading branch information...
1 parent 4a5425b commit 0ce4deeb8315c17de651e599bad1a5b0c73ee1f7 Joachim Kainz committed
Showing with 21 additions and 7 deletions.
  1. +16 −0 lib/backgrounder-launcher.js
  2. +5 −7 lib/backgrounder.js
View
16 lib/backgrounder-launcher.js
@@ -190,6 +190,22 @@ process.send = function(message, id) {
var json = JSON.stringify(msg);
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;
function getTitle(worker) {
View
12 lib/backgrounder.js
@@ -9,7 +9,7 @@ function getAvailableChild(manager) {
for(var idx = manager.lastUsed+1; idx < manager.children.length; idx++) {
var child = manager.children[idx];
- if (!child.pending) {
+ if (child && !child.pending) {
return manager.lastUsed = idx;
}
}
@@ -17,7 +17,7 @@ function getAvailableChild(manager) {
for(var idx = .0; idx < manager.children.length; idx++) {
var child = manager.children[idx];
- if (!child.pending) {
+ if (child && !child.pending) {
return manager.lastUsed = idx;
}
}
@@ -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)
//
function sendMessage(manager, id, message, callback) {
- console.log("send message %s", id);
var child = manager.children[id];
if (!child) {
@@ -136,6 +135,9 @@ function processMessage(child, message) {
else if (message.type === 'completed') {
processCompleted(child, message);
}
+ else if (message.type === 'terminating') {
+ child.restart();
+ }
else {
console.error("unexpected message %s", util.inspect(message));
}
@@ -202,7 +204,6 @@ function startChild(manager, module, config, idx, callback) {
return;
}
if (manager.children[idx] && manager.children[idx] != this) {
- console.log("already restarted");
return;
}
}
@@ -212,11 +213,8 @@ function startChild(manager, module, config, idx, callback) {
delete manager.children[idx];
}
};
- console.log("restarted %s", idx);
manager.children[idx] = child;
child.process.stdin.on('close', function(code, signal) {
- delete child.process;
- console.log("stdin %s closed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", idx);
child.restart();
});
if (config) {

0 comments on commit 0ce4dee

Please sign in to comment.
Something went wrong with that request. Please try again.