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

slow down status updates from mysql to better handle fast updates

to close #515
This commit is contained in:
Dave Conway-Jones 2019-02-01 22:15:22 +00:00
parent 9f0b46a9e1
commit d153034232
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 12 additions and 4 deletions

View File

@ -106,6 +106,8 @@ module.exports = function(RED) {
if (this.mydbConfig) {
this.mydbConfig.connect();
var node = this;
var busy = false;
var status = {};
node.mydbConfig.on("state", function(info) {
if (info === "connecting") { node.status({fill:"grey",shape:"ring",text:info}); }
else if (info === "connected") { node.status({fill:"green",shape:"dot",text:info}); }
@ -124,12 +126,12 @@ module.exports = function(RED) {
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
if (err) {
node.error(err,msg);
node.status({fill:"red",shape:"ring",text:"Error"});
status = {fill:"red",shape:"ring",text:"Error"};
}
else {
msg.payload = rows;
node.send(msg);
node.status({fill:"green",shape:"dot",text:"OK"});
status = {fill:"green",shape:"dot",text:"OK"};
}
});
}
@ -139,11 +141,17 @@ module.exports = function(RED) {
}
else {
node.error("Database not connected",msg);
node.status({fill:"red",shape:"ring",text:"not yet connected"});
status = {fill:"red",shape:"ring",text:"not yet connected"};
}
if (!busy) {
busy = true;
node.status(status);
node.tout = setTimeout(function() { busy = false; node.status(status); },500);
}
});
node.on('close', function () {
if (node.tout) { clearTimeout(node.tout); }
node.mydbConfig.removeAllListeners();
node.status({});
});

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-mysql",
"version" : "0.0.17",
"version" : "0.0.18",
"description" : "A Node-RED node to read and write to a MySQL database",
"dependencies" : {
"mysql" : "^2.16.0"