Prevent needless retention of node status messages

This commit is contained in:
Nick O'Leary
2020-11-16 21:04:38 +00:00
parent 42f3b70a22
commit 6ea978d83d
5 changed files with 50 additions and 17 deletions

View File

@@ -21,8 +21,11 @@ module.exports = function(RED) {
this.tosidebar = n.tosidebar;
if (this.tosidebar === undefined) { this.tosidebar = true; }
this.active = (n.active === null || typeof n.active === "undefined") || n.active;
if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); }
else { this.status({}); }
if (this.tostatus) {
this.status({fill:"grey", shape:"ring"});
this.oldState = "{}";
}
var hasStatExpression = (n.statusType === "jsonata");
var statExpression = hasStatExpression ? n.statusVal : null;
@@ -97,7 +100,11 @@ module.exports = function(RED) {
}
}
}
this.on("close", function() {
if (this.oldState) {
this.status({});
}
})
this.on("input", function(msg, send, done) {
if (msg.hasOwnProperty("status") && msg.status.hasOwnProperty("source") && msg.status.source.hasOwnProperty("id") && (msg.status.source.id === node.id)) {
done();
@@ -202,13 +209,8 @@ module.exports = function(RED) {
function setNodeState(node,state) {
if (state) {
node.active = true;
if (node.tostatus) { node.status({fill:"grey", shape:"dot"}); }
} else {
node.active = false;
if (node.tostatus && node.hasOwnProperty("oldStatus")) {
node.oldStatus.shape = "dot";
node.status(node.oldStatus);
}
}
}

View File

@@ -127,6 +127,8 @@ module.exports = function(RED) {
node.topic = n.topic;
node.outstandingTimers = [];
node.outstandingIntervals = [];
node.clearStatus = false;
var sandbox = {
console:console,
util:util,
@@ -163,6 +165,7 @@ module.exports = function(RED) {
node.on.apply(node, arguments);
},
status: function() {
node.clearStatus = true;
node.status.apply(node, arguments);
}
},
@@ -389,7 +392,9 @@ module.exports = function(RED) {
while (node.outstandingIntervals.length > 0) {
clearInterval(node.outstandingIntervals.pop());
}
node.status({});
if (node.clearStatus) {
node.status({});
}
});
promise.then(function (v) {