From 2b50bf38ec7b7aec6dd5b0870abf376677b02928 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 14 Dec 2022 11:45:33 +0000 Subject: [PATCH] Fix tail to update status and retry if file goes away and comes back --- storage/tail/28-tail.js | 4 ++++ storage/tail/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/storage/tail/28-tail.js b/storage/tail/28-tail.js index 0f741604..4bdb0fc7 100644 --- a/storage/tail/28-tail.js +++ b/storage/tail/28-tail.js @@ -16,6 +16,7 @@ module.exports = function(RED) { var fileTail = function() { if (fs.existsSync(node.filename)) { + node.status({ }); if (node.filetype === "text") { 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.status({ fill: "red",shape:"ring", text: "node-red:common.status.error" }); node.error(err.toString()); + if (err.code ==="ENOENT") { scheduleRestart(); } }); } else { @@ -51,6 +53,8 @@ module.exports = function(RED) { var scheduleRestart = function() { node.tout = setTimeout(function() { node.tout = null; + if (node.tail) { node.tail.unwatch(); } + delete node.tail; fileTail(); }, 10000); }; diff --git a/storage/tail/package.json b/storage/tail/package.json index d95ade61..a6d542cd 100644 --- a/storage/tail/package.json +++ b/storage/tail/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-tail", - "version": "0.3.2", + "version": "0.4.0", "description": "A node to tail files for Node-RED", "dependencies": { "tail": "^2.2.4"