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

delay node - change lifo property to toFront

add info to sidebar
add tests
This commit is contained in:
Dave Conway-Jones 2021-07-16 11:31:21 +01:00
parent d820f55358
commit a2b95dbb39
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
3 changed files with 62 additions and 1 deletions

View File

@ -253,7 +253,7 @@ 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.lifo) {
} else if (msg.toFront === true) {
node.buffer.unshift({msg: m, send: send, done: done});
node.reportDepth();
} else {

View File

@ -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,

View File

@ -789,6 +789,62 @@ describe('delay Node', function() {
});
});
it('can part push to front of rate limit queue', function(done) {
this.timeout(2000);
var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":1,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(delayNode, flow, function() {
var delayNode1 = helper.getNode("delayNode1");
var helperNode1 = helper.getNode("helperNode1");
var t = Date.now();
var c = 0;
helperNode1.on("input", function(msg) {
msg.should.have.a.property('payload');
msg.should.have.a.property('topic');
try {
if (msg.topic === "aoo") {
msg.payload.should.equal(1);
(Date.now() - t).should.be.approximately(2,50);
c = c + 1;
}
else if (msg.topic === "eoo") {
msg.payload.should.equal(1);
(Date.now() - t).should.be.approximately(4,50);
c = c + 1;
}
else if (msg.topic === "coo") {
msg.payload.should.equal(1);
(Date.now() - t).should.be.approximately(202,50);
c = c + 1;
}
else if (msg.topic === "boo") {
msg.payload.should.equal(1);
(Date.now() - t).should.be.approximately(406,50);
c = c + 1;
}
else if (msg.topic === "doo") {
msg.payload.should.equal(1);
(Date.now() - t).should.be.approximately(404,50);
c = c + 1;
}
if (c === 5) { done(); }
} catch(e) {
done(e);
}
});
// send test messages
delayNode1.receive({payload:1,topic:"aoo"});
setImmediate( function() { delayNode1.receive({payload:1,topic:"boo"}); } );
setImmediate( function() { delayNode1.receive({payload:1,topic:"coo",toFront:true}); } );
setImmediate( function() { delayNode1.receive({payload:1,topic:"doo"}); } );
setImmediate( function() { delayNode1.receive({payload:1,topic:"eoo",toFront:true}); } );
setImmediate( function() { delayNode1.receive({flush:1}); });
setTimeout( function() { delayNode1.receive({flush:1}); }, 200);
setTimeout( function() { delayNode1.receive({flush:4}); }, 400);
});
});
it('can reset rate limit queue', function(done) {
this.timeout(2000);
var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},