I have a sequence of task parameters.
For executting the task, i use a function node, which cache the sequence in the node context and send the first element of the cache on demand (via array.shift()
).
So this function node works a bit like the delay node. i thought, this is could be an additional mode of the delay node. What do you think?
[{"id":"67fe4939cb96aaea","type":"function","z":"e6998ea910456df2","name":"cache","func":"let payload = msg.payload\n\n\nfunction send_element() {\n let cache = context.get(\"cache\");\n const topic = context.get(\"original_topic\") || msg.topic;\n delete msg.original_topic\n if (cache.length == 0) {\n node.status({ fill: \"red\", shape: \"dot\", text: \"cache empty!\" });\n context.set(\"original_topic\",undefined)\n return\n }\n msg.payload = cache.shift()\n msg.topic = topic\n node.status({ fill: \"green\", shape: \"dot\", text: cache.length });\n node.send(msg);\n}\n\n\n\nif (msg.topic==\"save\") {\n context.set(\"cache\", payload);\n context.set(\"original_topic\",msg.original_topic)\n send_element()\n\n}\n\n\nif (msg.topic == \"get\") {\n send_element()\n}\n\n\nif (msg.topic == \"delete\") {\n context.set(\"cache\", []);\n node.status({ fill: \"red\", shape: \"dot\", text: 0 });\n return\n}\n\n\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"// Der Code hier wird ausgefĂĽhrt,\n// wenn der Node gestartet wird\nnode.status({ fill: \"red\", shape: \"dot\", text: \"cache empty!\" });","finalize":"","libs":[],"x":770,"y":4480,"wires":[["a45a8074af69afea"]]},{"id":"a45a8074af69afea","type":"delay","z":"e6998ea910456df2","name":"long_running_task","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":630,"y":4600,"wires":[["59f3d2bd842b10f3","5b026e831436d2e0"]]},{"id":"59f3d2bd842b10f3","type":"change","z":"e6998ea910456df2","name":"get","rules":[{"t":"set","p":"topic","pt":"msg","to":"get","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":4480,"wires":[["67fe4939cb96aaea"]]},{"id":"67e03d32e8c4c72f","type":"inject","z":"e6998ea910456df2","name":"Add Tasks","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"original_topic","v":"original_topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"save","payload":"[1,2,3,4,5,6,7,8,9,10]","payloadType":"jsonata","x":540,"y":4380,"wires":[["67fe4939cb96aaea"]]},{"id":"5b026e831436d2e0","type":"debug","z":"e6998ea910456df2","name":"debug 382","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":4600,"wires":[]}]