Hello,
I'm learning how to control loops in NR, but can't seem to debug this simple loop.
[{"id":"43361163d49b32dc","type":"inject","z":"82bb81a69c76160e","name":"Interval 5s","props":[{"p":"payload.time","v":"","vt":"date"},{"p":"delay","v":"5000","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":320,"y":2760,"wires":[["c7204267634c3125","bc2f710c2bd7dbf8"]]},{"id":"04d691146cc01a24","type":"delay","z":"82bb81a69c76160e","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":true,"outputs":1,"x":600,"y":2860,"wires":[["bc2f710c2bd7dbf8","c7204267634c3125"]]},{"id":"c7204267634c3125","type":"function","z":"82bb81a69c76160e","name":"","func":"\n\nif( !msg.payload.hasOwnProperty('counter'))\n{\n msg.payload.counter = 0;\n}\n\nmsg.payload.counter = msg.payload.counter+1;\n\n//msg.delay = 2000;\n// Sets the delay, in milliseconds, to be applied to the message. \n// This option only applies if the node is configured to allow the \n// message to override the configured default delay interval.\n\n//msg.rate = 2000;\n// Sets the rate value in milliseconds between messages. This node\n// overwrites the existing rate value defined in the node \n// configuration when it receives the message which contains msg.rate \n// value in milliSeconds. This option only applies if the node is \n// configured to allow the message to override the configured default \n// rate interval.\n\n//msg.reset = true;\n// If the received message has this property set to any value, all \n// outstanding messages held by the node are cleared without being sent.\n\nmsg.flush = 1;\n// If the received message has this property set to a numeric value \n// then that many messages will be released immediately. If set to any \n// other type (e.g. boolean), then all outstanding messages held by the \n// node are sent immediately.\n\nmsg.toFront = true;\n// When in rate limit mode, if the received message has this property \n// set to boolean true, then the message is pushed to the front of the \n// queue and will be released next. This can be used in combination with \n// msg.flush=1 to resend immediately. \n\n// Details\n\n// When configured to delay messages, the delay interval can be a fixed \n// value, a random value within a range or dynamically set for each message. \n// Each message is delayed independently of any other message, based on the \n// time of its arrival.\n\n// When configured to rate limit messages, their delivery is spread across \n// the configured time period. The status shows the number of messages \n// currently in the queue. It can optionally discard intermediate messages as \n// they arrive.\n\n// If set to allow override of the rate, the new rate will be applied \n// immediately, and will remain in effect until changed again, the node \n// is reset, or the flow is restarted.\n\n// The rate limiting can be applied to all messages, or group them according \n// to their msg.topic value. When grouping, intermediate messages are \n// automatically dropped. At each time interval, the node can either release \n// the most recent message for all topics, or release the most recent message \n// for the next topic.\n\n// Note: In rate limit mode the maximum queue depth can be set by a property \n// in your settings.js file. For example nodeMessageBufferMaxLength: 1000,\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":2760,"wires":[["04d691146cc01a24","bc2f710c2bd7dbf8"]]},{"id":"bc2f710c2bd7dbf8","type":"debug","z":"82bb81a69c76160e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":2660,"wires":[]},{"id":"e33eb763ec3dadbd","type":"inject","z":"82bb81a69c76160e","name":"Interval 60s","props":[{"p":"payload.time","v":"","vt":"date"},{"p":"delay","v":"60000","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":330,"y":2820,"wires":[["c7204267634c3125","bc2f710c2bd7dbf8"]]},{"id":"0c8981a1178e6d6d","type":"inject","z":"82bb81a69c76160e","name":"Interval 1s","props":[{"p":"payload.time","v":"","vt":"date"},{"p":"delay","v":"1000","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":320,"y":2700,"wires":[["c7204267634c3125","bc2f710c2bd7dbf8"]]},{"id":"c391c8ac785d77af","type":"comment","z":"82bb81a69c76160e","name":"Trigger every n seconds","info":"","x":360,"y":2640,"wires":[]},{"id":"52f90350a9123877","type":"inject","z":"82bb81a69c76160e","name":"STOP","props":[{"p":"payload.time","v":"","vt":"date"},{"p":"reset","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":2880,"wires":[["c7204267634c3125","bc2f710c2bd7dbf8"]]}]
What I intend is to have a single message going round the loop. It will wait 1, 5 or 60 seconds before being released. The function node should incease the loop counter - msg.payload.counter by 1. If the inject nodes are triggered, they wait time should be updated and the total messages in the system should remain at 1.
I want to use code like this to help schedule other flows so the system is not overloaded.
p.s. I can't get my head round rate limited vs delayed.