1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add node.done to exec node

This commit is contained in:
Nick O'Leary 2019-08-15 10:40:40 +01:00
parent 944b81b71c
commit 7bed967755
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -38,7 +38,7 @@ module.exports = function(RED) {
//node.error("Exec node timeout"); //node.error("Exec node timeout");
} }
this.on("input", function(msg) { this.on("input", function(msg, nodeSend, nodeDone) {
if (msg.hasOwnProperty("kill")) { if (msg.hasOwnProperty("kill")) {
if (typeof msg.kill !== "string" || msg.kill.length === 0 || !msg.kill.toUpperCase().startsWith("SIG") ) { msg.kill = "SIGTERM"; } if (typeof msg.kill !== "string" || msg.kill.length === 0 || !msg.kill.toUpperCase().startsWith("SIG") ) { msg.kill = "SIGTERM"; }
if (msg.hasOwnProperty("pid")) { if (msg.hasOwnProperty("pid")) {
@ -53,6 +53,7 @@ module.exports = function(RED) {
node.status({fill:"red",shape:"dot",text:"killed"}); node.status({fill:"red",shape:"dot",text:"killed"});
} }
} }
nodeDone();
} }
else { else {
var child; var child;
@ -85,14 +86,14 @@ module.exports = function(RED) {
// console.log('[exec] stdout: ' + data,child.pid); // console.log('[exec] stdout: ' + data,child.pid);
if (isUtf8(data)) { msg.payload = data.toString(); } if (isUtf8(data)) { msg.payload = data.toString(); }
else { msg.payload = data; } else { msg.payload = data; }
node.send([RED.util.cloneMessage(msg),null,null]); nodeSend([RED.util.cloneMessage(msg),null,null]);
} }
}); });
child.stderr.on('data', function (data) { child.stderr.on('data', function (data) {
if (node.activeProcesses.hasOwnProperty(child.pid) && node.activeProcesses[child.pid] !== null) { if (node.activeProcesses.hasOwnProperty(child.pid) && node.activeProcesses[child.pid] !== null) {
if (isUtf8(data)) { msg.payload = data.toString(); } if (isUtf8(data)) { msg.payload = data.toString(); }
else { msg.payload = Buffer.from(data); } else { msg.payload = Buffer.from(data); }
node.send([null,RED.util.cloneMessage(msg),null]); nodeSend([null,RED.util.cloneMessage(msg),null]);
} }
}); });
child.on('close', function (code,signal) { child.on('close', function (code,signal) {
@ -108,8 +109,9 @@ module.exports = function(RED) {
if (code === null) { node.status({fill:"red",shape:"dot",text:"killed"}); } if (code === null) { node.status({fill:"red",shape:"dot",text:"killed"}); }
else if (code < 0) { node.status({fill:"red",shape:"dot",text:"rc:"+code}); } else if (code < 0) { node.status({fill:"red",shape:"dot",text:"rc:"+code}); }
else { node.status({fill:"yellow",shape:"dot",text:"rc:"+code}); } else { node.status({fill:"yellow",shape:"dot",text:"rc:"+code}); }
node.send([null,null,RED.util.cloneMessage(msg)]); nodeSend([null,null,RED.util.cloneMessage(msg)]);
} }
nodeDone();
}); });
child.on('error', function (code) { child.on('error', function (code) {
if (child.tout) { clearTimeout(child.tout); } if (child.tout) { clearTimeout(child.tout); }
@ -154,9 +156,10 @@ module.exports = function(RED) {
msg.rc = msg3.payload; msg.rc = msg3.payload;
if (msg2) { msg2.rc = msg3.payload; } if (msg2) { msg2.rc = msg3.payload; }
} }
node.send([msg,msg2,msg3]); nodeSend([msg,msg2,msg3]);
if (child.tout) { clearTimeout(child.tout); } if (child.tout) { clearTimeout(child.tout); }
delete node.activeProcesses[child.pid]; delete node.activeProcesses[child.pid];
nodeDone();
}); });
node.status({fill:"blue",shape:"dot",text:"pid:"+child.pid}); node.status({fill:"blue",shape:"dot",text:"pid:"+child.pid});
child.on('error',function() {}); child.on('error',function() {});