mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Update 28-tail.js
This commit is contained in:
parent
28580c33ea
commit
8f634cff75
@ -41,11 +41,29 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.tout = setTimeout(function() { fileTail(); },10000);
|
scheduleRestart();
|
||||||
node.warn(RED._("tail.errors.filenotfound") + ": "+node.filename);
|
node.warn(RED._("tail.errors.filenotfound") + ": "+node.filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scheduleRestart = function() {
|
||||||
|
node.tout = setTimeout(function() {
|
||||||
|
node.tout = null;
|
||||||
|
fileTail();
|
||||||
|
}, 10000);
|
||||||
|
};
|
||||||
|
|
||||||
|
var cancelRestart = function() {
|
||||||
|
if (node.tout) {
|
||||||
|
clearTimeout(node.tout);
|
||||||
|
node.tout = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var isRestartPending = function() {
|
||||||
|
return !!node.tout;
|
||||||
|
};
|
||||||
|
|
||||||
if (node.filename !== "") {
|
if (node.filename !== "") {
|
||||||
node.status({});
|
node.status({});
|
||||||
fileTail();
|
fileTail();
|
||||||
@ -57,12 +75,12 @@ module.exports = function(RED) {
|
|||||||
} else if (msg.filename === "") {
|
} else if (msg.filename === "") {
|
||||||
node.filename = "";
|
node.filename = "";
|
||||||
if (node.tail) { node.tail.unwatch(); }
|
if (node.tail) { node.tail.unwatch(); }
|
||||||
if (node.tout) { clearTimeout(node.tout); }
|
cancelRestart();
|
||||||
node.status({ fill: "grey", text: "tail.state.stopped" });
|
node.status({ fill: "grey", text: "tail.state.stopped" });
|
||||||
} else {
|
} else {
|
||||||
node.filename = msg.filename;
|
node.filename = msg.filename;
|
||||||
if (node.tail) { node.tail.unwatch(); }
|
if (node.tail) { node.tail.unwatch(); }
|
||||||
if (!node.tout) { fileTail(); }
|
if (!isRestartPending()) { fileTail(); }
|
||||||
node.status({ fill: "green", text: node.filename });
|
node.status({ fill: "green", text: node.filename });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -72,7 +90,7 @@ module.exports = function(RED) {
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (node.tail) { node.tail.unwatch(); }
|
if (node.tail) { node.tail.unwatch(); }
|
||||||
delete node.tail;
|
delete node.tail;
|
||||||
if (node.tout) { clearTimeout(node.tout); }
|
cancelRestart();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user