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

add rate option to queue and timed modes. so a simple check box instead.

This commit is contained in:
Dave Conway-Jones 2021-04-22 11:02:34 +01:00
parent 87e816a7f5
commit 93971537b4
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
4 changed files with 30 additions and 19 deletions

View File

@ -63,7 +63,6 @@
<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>
@ -79,8 +78,11 @@
<option value="day" data-i18n="delay.label.units.day.singular"></option>
</select>
</div>
<div class="form-row" id="rate-override">
<label></label><input style="width:30px; vertical-align:baseline;" type="checkbox" id="node-input-allowrate"><label style="width: 250px;" for="node-input-allowrate" data-i18n="delay.allowrate"></label>
</div>
<div class="form-row" id="rate-details-drop">
<label></label><input style="width: 30px;" type="checkbox" id="node-input-drop"><label style="width: 250px;" for="node-input-drop" data-i18n="delay.dropmsg"></label>
<label></label><input style="width:30px;; vertical-align:baseline;" type="checkbox" id="node-input-drop"><label style="width: 250px;" for="node-input-drop" data-i18n="delay.dropmsg"></label>
</div>
<div class="form-row" id="rate-details-per-topic">
<label></label>
@ -111,7 +113,8 @@
randomFirst: {value:"1", required:true, validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
randomLast: {value:"5", required:true, validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
randomUnits: {value: "seconds"},
drop: {value:false}
drop: {value:false},
allowrate: {value:false}
},
inputs:1,
outputs:1,
@ -130,7 +133,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")||(this.pauseType == "ratev")) {
if (this.pauseType == "rate") {
return this._("delay.label.limit")+" "+rate;
} else if (this.pauseType == "timed") {
return this._("delay.label.limitTopic")+" "+rate;
@ -197,9 +200,6 @@
} 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');
@ -246,7 +246,7 @@
}).trigger("change");
$("#node-input-rate-type").on("change", function() {
if ((this.value === "all") || (this.value === "allo")) {
if (this.value === "all") {
$("#node-input-drop").attr('disabled',false).next().css("opacity",1)
$("#rate-details-per-topic").hide();
} else if (this.value === "topic") {
@ -263,8 +263,6 @@
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

@ -93,6 +93,8 @@ module.exports = function(RED) {
this.lastSent = null;
this.drop = n.drop;
this.droppedMsgs = 0;
this.allowrate = n.allowrate|| false;
this.fixedrate = this.rate;
var node = this;
function ourTimeout(handler, delay, clearHandler) {
@ -188,8 +190,7 @@ module.exports = function(RED) {
});
node.on("close", function() { clearDelayList(); });
}
else if ((node.pauseType === "rate")||(node.pauseType === "ratev")) {
var allowrate = (node.pauseType === "ratev") ? true : false;
else if (node.pauseType === "rate") {
node.on("input", function(msg, send, done) {
if (msg.hasOwnProperty("reset")) {
if (node.intervalID !== -1 ) {
@ -198,6 +199,7 @@ module.exports = function(RED) {
}
delete node.lastSent;
node.buffer = [];
node.rate = node.fixedrate;
node.status({text:"reset"});
done();
return;
@ -207,7 +209,7 @@ module.exports = function(RED) {
var m = RED.util.cloneMessage(msg);
delete m.flush;
if (node.intervalID !== -1) {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
if (node.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);
@ -222,7 +224,7 @@ module.exports = function(RED) {
}
}
else {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
node.rate = msg.rate;
}
send(m);
@ -246,7 +248,7 @@ module.exports = function(RED) {
node.send(msg);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
} else {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
if (node.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);
@ -260,7 +262,7 @@ module.exports = function(RED) {
}
}
} else {
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
node.rate = msg.rate;
}
var timeSinceLast;
@ -308,6 +310,11 @@ module.exports = function(RED) {
var hit;
node.on("input", function(msg, send, done) {
if (node.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);
}
if (!msg.hasOwnProperty("topic")) { msg.topic = "_none_"; }
hit = false;
for (var b in node.buffer) { // check if already in queue
@ -328,6 +335,7 @@ module.exports = function(RED) {
msgInfo.done();
}
node.buffer = [];
node.rate = node.fixedrate;
node.status({text:"reset"});
done();
}

View File

@ -25,7 +25,9 @@
<dt class="optional">rate <span class="property-type">number</span></dt>
<dd>Sets the rate value in milliseconds between messages.
This node overwrites the existing rate value defined in the node configuration
when it receives the message which contains <code>msg.rate</code> value.</dd>
when it receives the message which contains <code>msg.rate</code> value in milliSeconds.
This option only applies if the node is configured to allow the message to
override the configured default rate interval.</dd>
<dt class="optional">reset</dt>
<dd>If the received message has this property set to any value, all
outstanding messages held by the node are cleared without being sent.</dd>
@ -36,15 +38,17 @@
<h3>Details</h3>
<p>When configured to delay messages, the delay interval can be a fixed value,
a random value within a range or dynamically set for each message.
Each message is delayed independently of any other message, based on
Each message is delayed independently of any other message, based on
the time of its arrival.
</p>
<p>When configured to rate limit messages, their delivery is spread across
the configured time period. The status shows the number of messages currently in the queue.
It can optionally discard intermediate messages as they arrive.</p>
</p>
<p> If set to allow override of the rate, the new rate will be applied immediately,
and will remain in effect until changed again, the node is reset, or the flow is restarted.</p>
<p>The rate limiting can be applied to all messages, or group them according to
their <code>msg.topic</code> value. When grouping, intermerdiate messages are
their <code>msg.topic</code> value. When grouping, intermediate messages are
automatically dropped. At each time interval, the node can either release
the most recent message for all topics, or release the most recent message
for the next topic.

View File

@ -277,6 +277,7 @@
"rate": "Rate",
"msgper": "msg(s) per",
"dropmsg": "drop intermediate messages",
"allowrate": "allow msg.rate (in ms) to override rate",
"label": {
"delay": "delay",
"variable": "variable",