Need help with Delay node

I have searched through the forum but have not found what I am after. I want to read a CSV, parse it and use its data to simulate a sequence of activities to a time-series database. Each line of the CSV includes a delay value that I want to use in a Delay node in order to stage messages at correct intervals. The delay values vary by line. Parsing works fine, but the Delay node seems to be grouping all rows by the msg.delay. In this way all rows with msg.delay = 0 get sent in a burst even though they are not adjacent in the data. Then there is a pause for 2 seconds followed by the one message in the array where msg.delay = 2000. Then there is a 10-second pause followed by a single burst of all messages where msg.delay = 10000. The rows are taken out of order. For demonstration, I replaced the CSV/parsing with an injected array of data that looks similar to my parsed data. I have tried rate limiting, but then I seem to lose the ability to set each message's delay individually. What am I missing?

[{"id":"b4bc804c.84c02","type":"inject","z":"50e1c6b2.548378","name":"","topic":"","payload":"[{\"delay\":0,\"label\":\"Belt Speed\",\"value\":0},{\"delay\":0,\"label\":\"Batch Number\",\"value\":\"Sim1234\"},{\"delay\":2000,\"label\":\"Recipe Name\",\"value\":\"Original Recipe\"},{\"delay\":10000,\"label\":\"Batch Active\",\"value\":1},{\"delay\":0,\"label\":\"Belt Speed\",\"value\":0},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":30},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":62},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":90},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":123},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":128},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":132},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":134},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":136}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":690,"y":120,"wires":[["e5a730ba.3694d"]]},{"id":"e5a730ba.3694d","type":"split","z":"50e1c6b2.548378","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":820,"y":140,"wires":[["c62473ad.c799e"]]},{"id":"e2caaa59.5a47c8","type":"debug","z":"50e1c6b2.548378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":300,"wires":[]},{"id":"490c8ada.654ee4","type":"delay","z":"50e1c6b2.548378","name":"delay","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":930,"y":260,"wires":[["e2caaa59.5a47c8"]]},{"id":"c62473ad.c799e","type":"change","z":"50e1c6b2.548378","name":"set delay","rules":[{"t":"set","p":"delay","pt":"msg","to":"payload.delay","tot":"msg"},{"t":"delete","p":"payload.delay","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":200,"wires":[["490c8ada.654ee4"]]}]

The delay starts when the delay node receives the message not when it sends the previous one. If you send them all very close together then all the delays will start at close to the same time. If you wanted them all with the same delay then you could use rate limit mode, but you want separate delays on each.
I think I would look at using node-red-contrib-simple-message-queue with a delay node, using the fact that the delay node sends on a message to tell the queue to release the next one.

Colin, thank you so much for your prompt reply! Your suggestion worked perfectly. Here is my revised sample.

[{"id":"9f35edc7.d40d","type":"inject","z":"39a6a837.29b698","name":"","topic":"","payload":"[{\"delay\":0,\"label\":\"Belt Speed\",\"value\":0},{\"delay\":0,\"label\":\"Batch Number\",\"value\":\"Sim1234\"},{\"delay\":2000,\"label\":\"Recipe Name\",\"value\":\"Original Recipe\"},{\"delay\":10000,\"label\":\"Batch Active\",\"value\":1},{\"delay\":0,\"label\":\"Belt Speed\",\"value\":0},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":30},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":62},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":90},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":123},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":128},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":132},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":134},{\"delay\":10000,\"label\":\"Belt Speed\",\"value\":136}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":460,"wires":[["3e6e516f.a9c8be"]]},{"id":"3e6e516f.a9c8be","type":"split","z":"39a6a837.29b698","name":"load queue","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":460,"wires":[["772620eb.5baa5"]]},{"id":"b5839e29.fb60a","type":"debug","z":"39a6a837.29b698","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1050,"y":460,"wires":[]},{"id":"4a958030.8dfbf","type":"delay","z":"39a6a837.29b698","name":"delay","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":170,"y":540,"wires":[["5c7400b6.a32c1"]]},{"id":"48dac9cb.324098","type":"change","z":"39a6a837.29b698","name":"set delay","rules":[{"t":"set","p":"delay","pt":"msg","to":"payload.delay","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":460,"wires":[["4a958030.8dfbf","b5839e29.fb60a"]]},{"id":"772620eb.5baa5","type":"simple-queue","z":"39a6a837.29b698","name":"queue1","firstMessageBypass":true,"bypassInterval":"0","x":580,"y":460,"wires":[["48dac9cb.324098"]]},{"id":"5c7400b6.a32c1","type":"change","z":"39a6a837.29b698","name":"","rules":[{"t":"set","p":"trigger","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":540,"wires":[["772620eb.5baa5"]]}]
1 Like

Excellent.