restrict inject interval to less that 2^31 millisecs

(596 hrs, 24 days) to stop overflow causing fast loop. (defaults to 0)
to close #1485
This commit is contained in:
Dave Conway-Jones 2018-01-17 09:35:47 +00:00
parent 1921796d6d
commit 558a66fbe5
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 12 additions and 4 deletions

View File

@ -170,6 +170,8 @@ The default payload is a timestamp of the current time in millisecs since Januar
<p>By default, the node is triggered manually by clicking on its button within the editor. It can also be set to
inject at regular intervals or according to a schedule.</p>
<p>It can also be configured to inject once each time the flows are started.</p>
<p>The maximum <i>Interval</i> that can be specified is about 596 hours / 24 days. However if you are looking at intervals
greater than one day you should consider using a scheduler node that can cope with power outages and restarts.</p>
<p><b>Note</b>: The <i>"Interval between times"</i> and <i>"at a specific time"</i> options use the standard cron system.
This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time.
If you want every 20 minutes from now - use the <i>"interval"</i> option.</p>
@ -185,7 +187,7 @@ If you want every 20 minutes from now - use the <i>"interval"</i> option.</p>
topic: {value:""},
payload: {value:"", validate: RED.validators.typedInput("payloadType")},
payloadType: {value:"date"},
repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0))) }},
repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }},
crontab: {value:""},
once: {value:false},
onceDelay: {value:0.1}

View File

@ -27,9 +27,14 @@ module.exports = function(RED) {
this.crontab = n.crontab;
this.once = n.once;
this.onceDelay = (n.onceDelay || 0.1) * 1000;
var node = this;
this.interval_id = null;
this.cronjob = null;
var node = this;
if (node.repeat > 2147483) {
node.error(RED._("inject.errors.toolong", this));
delete node.repeat;
}
node.repeaterSetup = function () {
if (this.repeat && !isNaN(this.repeat) && this.repeat > 0) {

View File

@ -61,10 +61,11 @@
"on": "on",
"onstart": "Inject once after",
"onceDelay": "seconds, then",
"tip": "<b>Note:</b> \"interval between times\" and \"at a specific time\" will use cron.<br/>See info box for details.",
"tip": "<b>Note:</b> \"interval between times\" and \"at a specific time\" will use cron.<br/>\"interval\" should be less than 596 hours.<br/>See info box for details.",
"success": "Successfully injected: __label__",
"errors": {
"failed": "inject failed, see log for details"
"failed": "inject failed, see log for details",
"toolong": "Interval too large"
}
},
"catch": {