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

Delay node - Make msg.rate an optional override

This commit is contained in:
Dave Conway-Jones 2021-04-22 10:26:35 +01:00
parent 0f45b1da48
commit 87e816a7f5
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
3 changed files with 15 additions and 7 deletions

View File

@ -63,6 +63,7 @@
<label></label>
<select id="node-input-rate-type" style="width:270px !important">
<option value="all" data-i18n="delay.limitall"></option>
<option value="allo" data-i18n="delay.limitallo"></option>
<option value="topic" data-i18n="delay.limittopic"></option>
</select>
</div>
@ -129,7 +130,7 @@
return this._("delay.label.random");
} else {
var rate = this.rate+" msg/"+(this.rateUnits ? (this.nbRateUnits > 1 ? this.nbRateUnits : '') + this.rateUnits.charAt(0) : "s");
if (this.pauseType == "rate") {
if ((this.pauseType == "rate")||(this.pauseType == "ratev")) {
return this._("delay.label.limit")+" "+rate;
} else if (this.pauseType == "timed") {
return this._("delay.label.limitTopic")+" "+rate;
@ -196,6 +197,9 @@
} else if (this.pauseType == "rate") {
$("#node-input-delay-action").val('rate');
$("#node-input-rate-type").val('all');
} else if (this.pauseType == "ratev") {
$("#node-input-delay-action").val('rate');
$("#node-input-rate-type").val('allo');
} else if (this.pauseType == "queue") {
$("#node-input-delay-action").val('rate');
$("#node-input-rate-type").val('topic');
@ -242,7 +246,7 @@
}).trigger("change");
$("#node-input-rate-type").on("change", function() {
if (this.value === "all") {
if ((this.value === "all") || (this.value === "allo")) {
$("#node-input-drop").attr('disabled',false).next().css("opacity",1)
$("#rate-details-per-topic").hide();
} else if (this.value === "topic") {
@ -259,6 +263,8 @@
action = $("#node-input-rate-type").val();
if (action === "all") {
this.pauseType = "rate";
} else if (action === "allo") {
this.pauseType = "ratev";
} else {
this.pauseType = $("#node-input-rate-topic-type").val();
}

View File

@ -188,7 +188,8 @@ module.exports = function(RED) {
});
node.on("close", function() { clearDelayList(); });
}
else if (node.pauseType === "rate") {
else if ((node.pauseType === "rate")||(node.pauseType === "ratev")) {
var allowrate = (node.pauseType === "ratev") ? true : false;
node.on("input", function(msg, send, done) {
if (msg.hasOwnProperty("reset")) {
if (node.intervalID !== -1 ) {
@ -206,7 +207,7 @@ module.exports = function(RED) {
var m = RED.util.cloneMessage(msg);
delete m.flush;
if (node.intervalID !== -1) {
if (msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
node.rate = msg.rate;
clearInterval(node.intervalID);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
@ -221,7 +222,7 @@ module.exports = function(RED) {
}
}
else {
if (msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
node.rate = msg.rate;
}
send(m);
@ -245,7 +246,7 @@ module.exports = function(RED) {
node.send(msg);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
} else {
if (msg.hasOwnProperty("rate") && node.rate !== msg.rate) {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
node.rate = msg.rate;
clearInterval(node.intervalID);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
@ -259,7 +260,7 @@ module.exports = function(RED) {
}
}
} else {
if (msg.hasOwnProperty("rate")) {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
node.rate = msg.rate;
}
var timeSinceLast;

View File

@ -259,6 +259,7 @@
"randomdelay": "Random delay",
"limitrate": "Rate Limit",
"limitall": "All messages",
"limitallo": "All messages (allow rate override)",
"limittopic": "For each msg.topic",
"fairqueue": "Send each topic in turn",
"timedqueue": "Send all topics",