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

Fix tail to update status

and retry if file goes away and comes back
This commit is contained in:
Dave Conway-Jones 2022-12-14 11:45:33 +00:00
parent 2da42c9495
commit 2b50bf38ec
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 5 additions and 1 deletions

View File

@ -16,6 +16,7 @@ module.exports = function(RED) {
var fileTail = function() { var fileTail = function() {
if (fs.existsSync(node.filename)) { if (fs.existsSync(node.filename)) {
node.status({ });
if (node.filetype === "text") { if (node.filetype === "text") {
node.tail = new Tail(node.filename,{separator:node.split, flushAtEOF:true}); node.tail = new Tail(node.filename,{separator:node.split, flushAtEOF:true});
} }
@ -40,6 +41,7 @@ module.exports = function(RED) {
node.tail.on("error", function(err) { node.tail.on("error", function(err) {
node.status({ fill: "red",shape:"ring", text: "node-red:common.status.error" }); node.status({ fill: "red",shape:"ring", text: "node-red:common.status.error" });
node.error(err.toString()); node.error(err.toString());
if (err.code ==="ENOENT") { scheduleRestart(); }
}); });
} }
else { else {
@ -51,6 +53,8 @@ module.exports = function(RED) {
var scheduleRestart = function() { var scheduleRestart = function() {
node.tout = setTimeout(function() { node.tout = setTimeout(function() {
node.tout = null; node.tout = null;
if (node.tail) { node.tail.unwatch(); }
delete node.tail;
fileTail(); fileTail();
}, 10000); }, 10000);
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-node-tail", "name": "node-red-node-tail",
"version": "0.3.2", "version": "0.4.0",
"description": "A node to tail files for Node-RED", "description": "A node to tail files for Node-RED",
"dependencies": { "dependencies": {
"tail": "^2.2.4" "tail": "^2.2.4"