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:
parent
0f45b1da48
commit
87e816a7f5
@ -63,6 +63,7 @@
|
|||||||
<label></label>
|
<label></label>
|
||||||
<select id="node-input-rate-type" style="width:270px !important">
|
<select id="node-input-rate-type" style="width:270px !important">
|
||||||
<option value="all" data-i18n="delay.limitall"></option>
|
<option value="all" data-i18n="delay.limitall"></option>
|
||||||
|
<option value="allo" data-i18n="delay.limitallo"></option>
|
||||||
<option value="topic" data-i18n="delay.limittopic"></option>
|
<option value="topic" data-i18n="delay.limittopic"></option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -129,7 +130,7 @@
|
|||||||
return this._("delay.label.random");
|
return this._("delay.label.random");
|
||||||
} else {
|
} else {
|
||||||
var rate = this.rate+" msg/"+(this.rateUnits ? (this.nbRateUnits > 1 ? this.nbRateUnits : '') + this.rateUnits.charAt(0) : "s");
|
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;
|
return this._("delay.label.limit")+" "+rate;
|
||||||
} else if (this.pauseType == "timed") {
|
} else if (this.pauseType == "timed") {
|
||||||
return this._("delay.label.limitTopic")+" "+rate;
|
return this._("delay.label.limitTopic")+" "+rate;
|
||||||
@ -196,6 +197,9 @@
|
|||||||
} else if (this.pauseType == "rate") {
|
} else if (this.pauseType == "rate") {
|
||||||
$("#node-input-delay-action").val('rate');
|
$("#node-input-delay-action").val('rate');
|
||||||
$("#node-input-rate-type").val('all');
|
$("#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") {
|
} else if (this.pauseType == "queue") {
|
||||||
$("#node-input-delay-action").val('rate');
|
$("#node-input-delay-action").val('rate');
|
||||||
$("#node-input-rate-type").val('topic');
|
$("#node-input-rate-type").val('topic');
|
||||||
@ -242,7 +246,7 @@
|
|||||||
}).trigger("change");
|
}).trigger("change");
|
||||||
|
|
||||||
$("#node-input-rate-type").on("change", function() {
|
$("#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)
|
$("#node-input-drop").attr('disabled',false).next().css("opacity",1)
|
||||||
$("#rate-details-per-topic").hide();
|
$("#rate-details-per-topic").hide();
|
||||||
} else if (this.value === "topic") {
|
} else if (this.value === "topic") {
|
||||||
@ -259,6 +263,8 @@
|
|||||||
action = $("#node-input-rate-type").val();
|
action = $("#node-input-rate-type").val();
|
||||||
if (action === "all") {
|
if (action === "all") {
|
||||||
this.pauseType = "rate";
|
this.pauseType = "rate";
|
||||||
|
} else if (action === "allo") {
|
||||||
|
this.pauseType = "ratev";
|
||||||
} else {
|
} else {
|
||||||
this.pauseType = $("#node-input-rate-topic-type").val();
|
this.pauseType = $("#node-input-rate-topic-type").val();
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,8 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
node.on("close", function() { clearDelayList(); });
|
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) {
|
node.on("input", function(msg, send, done) {
|
||||||
if (msg.hasOwnProperty("reset")) {
|
if (msg.hasOwnProperty("reset")) {
|
||||||
if (node.intervalID !== -1 ) {
|
if (node.intervalID !== -1 ) {
|
||||||
@ -206,7 +207,7 @@ module.exports = function(RED) {
|
|||||||
var m = RED.util.cloneMessage(msg);
|
var m = RED.util.cloneMessage(msg);
|
||||||
delete m.flush;
|
delete m.flush;
|
||||||
if (node.intervalID !== -1) {
|
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;
|
node.rate = msg.rate;
|
||||||
clearInterval(node.intervalID);
|
clearInterval(node.intervalID);
|
||||||
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
||||||
@ -221,7 +222,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
|
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
|
||||||
node.rate = msg.rate;
|
node.rate = msg.rate;
|
||||||
}
|
}
|
||||||
send(m);
|
send(m);
|
||||||
@ -245,7 +246,7 @@ module.exports = function(RED) {
|
|||||||
node.send(msg);
|
node.send(msg);
|
||||||
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
||||||
} else {
|
} 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;
|
node.rate = msg.rate;
|
||||||
clearInterval(node.intervalID);
|
clearInterval(node.intervalID);
|
||||||
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
||||||
@ -259,7 +260,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (msg.hasOwnProperty("rate")) {
|
if (allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
|
||||||
node.rate = msg.rate;
|
node.rate = msg.rate;
|
||||||
}
|
}
|
||||||
var timeSinceLast;
|
var timeSinceLast;
|
||||||
|
@ -259,6 +259,7 @@
|
|||||||
"randomdelay": "Random delay",
|
"randomdelay": "Random delay",
|
||||||
"limitrate": "Rate Limit",
|
"limitrate": "Rate Limit",
|
||||||
"limitall": "All messages",
|
"limitall": "All messages",
|
||||||
|
"limitallo": "All messages (allow rate override)",
|
||||||
"limittopic": "For each msg.topic",
|
"limittopic": "For each msg.topic",
|
||||||
"fairqueue": "Send each topic in turn",
|
"fairqueue": "Send each topic in turn",
|
||||||
"timedqueue": "Send all topics",
|
"timedqueue": "Send all topics",
|
||||||
|
Loading…
Reference in New Issue
Block a user