mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix some layout issues in the config popup and made the rate limit mode shut down the timer and make sure it sends the first message straight away when the buffer is empty.
This commit is contained in:
parent
56da5faae2
commit
25d8a59d6c
@ -18,17 +18,16 @@
|
||||
<script type="text/x-red" data-template-name="delay">
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-pauseType"><i class="icon-tasks"></i> Type</label>
|
||||
<select id="node-input-pauseType">
|
||||
<option value="delay">Delay</option>
|
||||
<option value="rate">Rate Limit</option>
|
||||
<label for="node-input-pauseType"><i class="icon-tasks"></i> Action</label>
|
||||
<select id="node-input-pauseType" style="width:270px !important">
|
||||
<option value="delay">Delay message</option>
|
||||
<option value="rate">Limit rate to</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="delay-details" class="form-row">
|
||||
<label for="node-input-timeout"><i class="icon-wrench"></i> Delay</label>
|
||||
<input type="text" id="node-input-timeout" placeholder="Time">
|
||||
<label for="node-input-timeoutUnits"> For </label>
|
||||
<select id="node-input-timeoutUnits">
|
||||
<label for="node-input-timeout"><i class="icon-time"></i> For</label>
|
||||
<input type="text" id="node-input-timeout" placeholder="Time" style="direction:rtl; width:50px !important">
|
||||
<select id="node-input-timeoutUnits" style="width:200px !important">
|
||||
<option value="milliseconds">Milliseconds</option>
|
||||
<option value="seconds">Seconds</option>
|
||||
<option value="minutes">Minutes</option>
|
||||
@ -38,10 +37,10 @@
|
||||
</div>
|
||||
|
||||
<div id="rate-details" class="form-row">
|
||||
<label for="node-input-rate"><i class="icon-wrench"></i> Rate</label>
|
||||
<input type="text" id="node-input-rate" placeholder="msg/second">
|
||||
<label for="node-input-rateUnits"> Per </label>
|
||||
<select id="node-input-rateUnits">
|
||||
<label for="node-input-rate"><i class="icon-time"></i> To</label>
|
||||
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:50px !important">
|
||||
<label for="node-input-reateUnits">message(s) per</label>
|
||||
<select id="node-input-rateUnits" style="width:140px !important">
|
||||
<option value="second">Second</option>
|
||||
<option value="minute">Minute</option>
|
||||
<option value="hour">Hour</option>
|
||||
@ -54,7 +53,6 @@
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
|
||||
<div class="form-tips">Delay value in seconds, Rate value in messages per second</div>
|
||||
</script>
|
||||
|
||||
<!-- Next, some simple help text is provided for the node. -->
|
||||
@ -93,6 +91,9 @@
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
$( "#node-input-timeout" ).spinner();
|
||||
$( "#node-input-rate" ).spinner();
|
||||
|
||||
if (this.pauseType == "delay") {
|
||||
$("#delay-details").show();
|
||||
$("#rate-details").hide();
|
||||
@ -114,7 +115,7 @@
|
||||
} else if (this.value == "rate") {
|
||||
$("#delay-details").hide();
|
||||
$("#rate-details").show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -48,13 +48,11 @@ function DelayNode(n) {
|
||||
} else if (n.rateUnits == "day") {
|
||||
this.rate = (24 * 60 * 60 * 1000)/n.rate;
|
||||
}
|
||||
|
||||
console.log(this.timeoutUnits + " - " + n.timeout + " = " + this.timeout);
|
||||
console.log(this.rateUnits + " - " + n.rate + " = " + this.rate);
|
||||
|
||||
this.name = n.name;
|
||||
this.idList = [];
|
||||
this.buffer = [];
|
||||
this.intervalID = -1;
|
||||
var node= this;
|
||||
|
||||
if (this.pauseType == "delay") {
|
||||
@ -69,21 +67,31 @@ function DelayNode(n) {
|
||||
});
|
||||
} else if (this.pauseType == "rate") {
|
||||
|
||||
this.intervalID = setInterval(function() {
|
||||
if (node.buffer.length > 0) {
|
||||
node.send(node.buffer.shift());
|
||||
}
|
||||
},this.rate);
|
||||
|
||||
this.on("input", function(msg) {
|
||||
this.buffer.push(msg);
|
||||
if (this.buffer.length > 1000) {
|
||||
this.warn(this.name + " buffer exceeded 1000 messages");
|
||||
if ( node.intervalID != -1) {
|
||||
node.buffer.push(msg);
|
||||
if (node.buffer.length > 1000) {
|
||||
node.warn(this.name + " buffer exceeded 1000 messages");
|
||||
}
|
||||
} else {
|
||||
node.send(msg);
|
||||
node.intervalID = setInterval(function() {
|
||||
if (node.buffer.length == 0) {
|
||||
clearInterval(node.intervalID);
|
||||
node.intervalID = -1;
|
||||
}
|
||||
|
||||
if (node.buffer.length > 0) {
|
||||
node.send(node.buffer.shift());
|
||||
}
|
||||
},node.rate);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// register node
|
||||
RED.nodes.registerType("delay",DelayNode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user