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

tidy up ping node listeners

This commit is contained in:
Dave Conway-Jones 2020-07-01 11:16:20 +01:00
parent 41d9f18608
commit 5ba989f09d
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
2 changed files with 21 additions and 15 deletions

View File

@ -42,7 +42,13 @@ module.exports = function(RED) {
//monitor every spawned process & SIGINT if too long //monitor every spawned process & SIGINT if too long
var spawnTout = setTimeout(() => { var spawnTout = setTimeout(() => {
node.log(`ping - Host '${hostOptions.host}' process timeout - sending SIGINT`) node.log(`ping - Host '${hostOptions.host}' process timeout - sending SIGINT`)
try{if(ex && ex.pid){ ex.kill("SIGINT"); }} catch(e){console.warn(e)} try {
if (ex && ex.pid) {
ex.removeAllListeners();
ex.kill("SIGINT");
}
}
catch(e) { console.warn(e) }
}, hostOptions.timeout+1000); //add 1s for grace }, hostOptions.timeout+1000); //add 1s for grace
var res = false; var res = false;
@ -50,9 +56,11 @@ module.exports = function(RED) {
var fail = false; var fail = false;
//var regex = /from.*time.(.*)ms/; //var regex = /from.*time.(.*)ms/;
var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/; var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/;
if (ex && ex.hasOwnProperty("stdout")) {
ex.stdout.on("data", function (data) { ex.stdout.on("data", function (data) {
line += data.toString(); line += data.toString();
}); });
}
ex.on("exit", function (err) { ex.on("exit", function (err) {
clearTimeout(spawnTout); clearTimeout(spawnTout);
}); });
@ -127,8 +135,6 @@ module.exports = function(RED) {
this.on("close", function() { this.on("close", function() {
clearPingInterval(); clearPingInterval();
}); });
} }
RED.nodes.registerType("ping",PingNode); RED.nodes.registerType("ping",PingNode);
} }

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-ping", "name" : "node-red-node-ping",
"version" : "0.2.0", "version" : "0.2.1",
"description" : "A Node-RED node to ping a remote server, for use as a keep-alive check.", "description" : "A Node-RED node to ping a remote server, for use as a keep-alive check.",
"dependencies" : { "dependencies" : {
}, },