mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Prevent needless retention of node status messages
This commit is contained in:
parent
42f3b70a22
commit
6ea978d83d
@ -33,8 +33,6 @@ var activeConnections = [];
|
|||||||
|
|
||||||
var anonymousUser;
|
var anonymousUser;
|
||||||
|
|
||||||
var retained = {};
|
|
||||||
|
|
||||||
var heartbeatTimer;
|
var heartbeatTimer;
|
||||||
var lastSentTime;
|
var lastSentTime;
|
||||||
|
|
||||||
|
@ -21,8 +21,11 @@ module.exports = function(RED) {
|
|||||||
this.tosidebar = n.tosidebar;
|
this.tosidebar = n.tosidebar;
|
||||||
if (this.tosidebar === undefined) { this.tosidebar = true; }
|
if (this.tosidebar === undefined) { this.tosidebar = true; }
|
||||||
this.active = (n.active === null || typeof n.active === "undefined") || n.active;
|
this.active = (n.active === null || typeof n.active === "undefined") || n.active;
|
||||||
if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); }
|
if (this.tostatus) {
|
||||||
else { this.status({}); }
|
this.status({fill:"grey", shape:"ring"});
|
||||||
|
this.oldState = "{}";
|
||||||
|
}
|
||||||
|
|
||||||
var hasStatExpression = (n.statusType === "jsonata");
|
var hasStatExpression = (n.statusType === "jsonata");
|
||||||
var statExpression = hasStatExpression ? n.statusVal : null;
|
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) {
|
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)) {
|
if (msg.hasOwnProperty("status") && msg.status.hasOwnProperty("source") && msg.status.source.hasOwnProperty("id") && (msg.status.source.id === node.id)) {
|
||||||
done();
|
done();
|
||||||
@ -202,13 +209,8 @@ module.exports = function(RED) {
|
|||||||
function setNodeState(node,state) {
|
function setNodeState(node,state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
node.active = true;
|
node.active = true;
|
||||||
if (node.tostatus) { node.status({fill:"grey", shape:"dot"}); }
|
|
||||||
} else {
|
} else {
|
||||||
node.active = false;
|
node.active = false;
|
||||||
if (node.tostatus && node.hasOwnProperty("oldStatus")) {
|
|
||||||
node.oldStatus.shape = "dot";
|
|
||||||
node.status(node.oldStatus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +127,8 @@ module.exports = function(RED) {
|
|||||||
node.topic = n.topic;
|
node.topic = n.topic;
|
||||||
node.outstandingTimers = [];
|
node.outstandingTimers = [];
|
||||||
node.outstandingIntervals = [];
|
node.outstandingIntervals = [];
|
||||||
|
node.clearStatus = false;
|
||||||
|
|
||||||
var sandbox = {
|
var sandbox = {
|
||||||
console:console,
|
console:console,
|
||||||
util:util,
|
util:util,
|
||||||
@ -163,6 +165,7 @@ module.exports = function(RED) {
|
|||||||
node.on.apply(node, arguments);
|
node.on.apply(node, arguments);
|
||||||
},
|
},
|
||||||
status: function() {
|
status: function() {
|
||||||
|
node.clearStatus = true;
|
||||||
node.status.apply(node, arguments);
|
node.status.apply(node, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -389,7 +392,9 @@ module.exports = function(RED) {
|
|||||||
while (node.outstandingIntervals.length > 0) {
|
while (node.outstandingIntervals.length > 0) {
|
||||||
clearInterval(node.outstandingIntervals.pop());
|
clearInterval(node.outstandingIntervals.pop());
|
||||||
}
|
}
|
||||||
node.status({});
|
if (node.clearStatus) {
|
||||||
|
node.status({});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
promise.then(function (v) {
|
promise.then(function (v) {
|
||||||
|
@ -38,12 +38,20 @@ function handleCommsEvent(event) {
|
|||||||
publish(event.topic,event.data,event.retain);
|
publish(event.topic,event.data,event.retain);
|
||||||
}
|
}
|
||||||
function handleStatusEvent(event) {
|
function handleStatusEvent(event) {
|
||||||
var status = {
|
if (!event.status) {
|
||||||
text: event.status.text,
|
delete retained["status/"+event.id]
|
||||||
fill: event.status.fill,
|
} else if (!event.status.text && !event.status.fill && !event.status.shape) {
|
||||||
shape: event.status.shape
|
if (retained["status/"+event.id]) {
|
||||||
};
|
publish("status/"+event.id,{},false);
|
||||||
publish("status/"+event.id,status,true);
|
}
|
||||||
|
} else {
|
||||||
|
var status = {
|
||||||
|
text: event.status.text,
|
||||||
|
fill: event.status.fill,
|
||||||
|
shape: event.status.shape
|
||||||
|
};
|
||||||
|
publish("status/"+event.id,status,true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function handleRuntimeEvent(event) {
|
function handleRuntimeEvent(event) {
|
||||||
runtime.log.trace("runtime event: "+JSON.stringify(event));
|
runtime.log.trace("runtime event: "+JSON.stringify(event));
|
||||||
|
@ -18,6 +18,7 @@ const clone = require("clone");
|
|||||||
const Flow = require('./Flow').Flow;
|
const Flow = require('./Flow').Flow;
|
||||||
const context = require('../nodes/context');
|
const context = require('../nodes/context');
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
const events = require("../events");
|
||||||
|
|
||||||
const redUtil = require("@node-red/util").util;
|
const redUtil = require("@node-red/util").util;
|
||||||
const flowUtil = require("./util");
|
const flowUtil = require("./util");
|
||||||
@ -308,7 +309,26 @@ class Subflow extends Flow {
|
|||||||
super.start(diff);
|
super.start(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop this subflow.
|
||||||
|
* The `stopList` argument helps define what needs to be stopped in the case
|
||||||
|
* of a modified-nodes/flows type deploy.
|
||||||
|
* @param {[type]} stopList [description]
|
||||||
|
* @param {[type]} removedList [description]
|
||||||
|
* @return {[type]} [description]
|
||||||
|
*/
|
||||||
|
stop(stopList, removedList) {
|
||||||
|
const nodes = Object.keys(this.activeNodes);
|
||||||
|
return super.stop(stopList, removedList).then(res => {
|
||||||
|
nodes.forEach(id => {
|
||||||
|
events.emit("node-status",{
|
||||||
|
id: id
|
||||||
|
});
|
||||||
|
})
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Get environment variable of subflow
|
* Get environment variable of subflow
|
||||||
* @param {String} name name of env var
|
* @param {String} name name of env var
|
||||||
|
Loading…
Reference in New Issue
Block a user