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() {
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);
};

View File

@ -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"