mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #3069 from node-red/delay-push-to-front
Add push to front of rate limit queue.
This commit is contained in:
@@ -154,6 +154,7 @@ module.exports = function(RED) {
|
||||
}, 15 * 1000);
|
||||
node.on("close", function() { clearInterval(loggerId); });
|
||||
|
||||
// The delay type modes
|
||||
if (node.pauseType === "delay") {
|
||||
node.on("input", function(msg, send, done) {
|
||||
var id = ourTimeout(function() {
|
||||
@@ -199,6 +200,29 @@ module.exports = function(RED) {
|
||||
});
|
||||
node.on("close", function() { clearDelayList(); });
|
||||
}
|
||||
else if (node.pauseType === "random") {
|
||||
node.on("input", function(msg, send, done) {
|
||||
var wait = node.randomFirst + (node.diff * Math.random());
|
||||
var id = ourTimeout(function() {
|
||||
node.idList.splice(node.idList.indexOf(id),1);
|
||||
send(msg);
|
||||
if (node.timeout >= 1000) {
|
||||
node.status({fill:"blue",shape:"dot",text:node.idList.length});
|
||||
}
|
||||
done();
|
||||
}, wait, () => done());
|
||||
if (Object.keys(msg).length === 2 && msg.hasOwnProperty("flush")) { id.clear(); }
|
||||
else { node.idList.push(id); }
|
||||
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
|
||||
if (msg.hasOwnProperty("flush")) { flushDelayList(msg.flush); done(); }
|
||||
if (node.timeout >= 1000) {
|
||||
node.status({fill:"blue",shape:"dot",text:node.idList.length});
|
||||
}
|
||||
});
|
||||
node.on("close", function() { clearDelayList(); });
|
||||
}
|
||||
|
||||
// The rate limit/queue type modes
|
||||
else if (node.pauseType === "rate") {
|
||||
node.on("input", function(msg, send, done) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
@@ -217,6 +241,7 @@ module.exports = function(RED) {
|
||||
if (!node.drop) {
|
||||
var m = RED.util.cloneMessage(msg);
|
||||
delete m.flush;
|
||||
delete m.lifo;
|
||||
if (Object.keys(m).length > 1) {
|
||||
if (node.intervalID !== -1) {
|
||||
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
|
||||
@@ -228,6 +253,9 @@ module.exports = function(RED) {
|
||||
if ((max_msgs > 0) && (node.buffer.length >= max_msgs)) {
|
||||
node.buffer = [];
|
||||
node.error(RED._("delay.errors.too-many"), msg);
|
||||
} else if (msg.toFront === true) {
|
||||
node.buffer.unshift({msg: m, send: send, done: done});
|
||||
node.reportDepth();
|
||||
} else {
|
||||
node.buffer.push({msg: m, send: send, done: done});
|
||||
node.reportDepth();
|
||||
@@ -309,6 +337,8 @@ module.exports = function(RED) {
|
||||
node.status({});
|
||||
});
|
||||
}
|
||||
|
||||
// The topic based fair queue and last arrived on all topics queue
|
||||
else if ((node.pauseType === "queue") || (node.pauseType === "timed")) {
|
||||
node.intervalID = setInterval(function() {
|
||||
if (node.pauseType === "queue") {
|
||||
@@ -385,27 +415,6 @@ module.exports = function(RED) {
|
||||
node.status({});
|
||||
});
|
||||
}
|
||||
else if (node.pauseType === "random") {
|
||||
node.on("input", function(msg, send, done) {
|
||||
var wait = node.randomFirst + (node.diff * Math.random());
|
||||
var id = ourTimeout(function() {
|
||||
node.idList.splice(node.idList.indexOf(id),1);
|
||||
send(msg);
|
||||
if (node.timeout >= 1000) {
|
||||
node.status({fill:"blue",shape:"dot",text:node.idList.length});
|
||||
}
|
||||
done();
|
||||
}, wait, () => done());
|
||||
if (Object.keys(msg).length === 2 && msg.hasOwnProperty("flush")) { id.clear(); }
|
||||
else { node.idList.push(id); }
|
||||
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
|
||||
if (msg.hasOwnProperty("flush")) { flushDelayList(msg.flush); done(); }
|
||||
if (node.timeout >= 1000) {
|
||||
node.status({fill:"blue",shape:"dot",text:node.idList.length});
|
||||
}
|
||||
});
|
||||
node.on("close", function() { clearDelayList(); });
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("delay",DelayNode);
|
||||
}
|
||||
|
@@ -35,6 +35,11 @@
|
||||
<dd>If the received message has this property set to a numeric value then that many messages
|
||||
will be released immediately. If set to any other type (e.g. boolean), then all
|
||||
outstanding messages held by the node are sent immediately.</dd>
|
||||
<dt class="optional">toFront</dt>
|
||||
<dd>When in rate limit mode, if the received message has this property set to boolean <code>true</code>,
|
||||
then the message is pushed to the front of the queue and will be released next.
|
||||
This can be used in combination with <code>msg.flush=1</code> to resend immediately.
|
||||
</dd>
|
||||
</dl>
|
||||
<h3>Details</h3>
|
||||
<p>When configured to delay messages, the delay interval can be a fixed value,
|
||||
@@ -46,7 +51,7 @@
|
||||
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,
|
||||
<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, intermediate messages are
|
||||
@@ -54,4 +59,6 @@
|
||||
the most recent message for all topics, or release the most recent message
|
||||
for the next topic.
|
||||
</p>
|
||||
<p><b>Note</b>: In rate limit mode the maximum queue depth can be set by a property in your
|
||||
<i>settings.js</i> file. For example <code>nodeMessageBufferMaxLength: 1000,</code>
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user