1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/packages/node_modules/@node-red/nodes/examples/function/trigger/04 - Timeout processing using trigger node.json

1 line
3.3 KiB
JSON
Raw Permalink Normal View History

[{"id":"d24083e7.fedc7","type":"comment","z":"58cb85a8.82904c","name":"Timeout processing using trigger node","info":"It is possible to configure timeout processing by combining two Trigger nodes. \n\nIn the first Trigger node settings panel, `send second message to separate output` checkbox is checked. With this specification, this trigger node will have two output ports. When the node receives an input message, it outputs the message to the first port, and after a specified period of time, it outputs the specified message to the second port.\n\nThe second trigger node is specified to handle each message ID (`msg._msgid`). This means that only the first received message among the messages with the same ID is transmitted. The time specified for it represents the retention time of information for message filtering and must be longer than the processing time for the timeout.\n","x":190,"y":60,"wires":[]},{"id":"8dcb51d5.90fbb","type":"inject","z":"58cb85a8.82904c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":160,"wires":[["69b526f1.347808"]]},{"id":"3b2238f8.71f6c8","type":"debug","z":"58cb85a8.82904c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":200,"wires":[]},{"id":"69b526f1.347808","type":"trigger","z":"58cb85a8.82904c","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":320,"y":200,"wires":[["3802c45b.84121c"],["a3c01d51.86cbb"]]},{"id":"7096b59a.c265fc","type":"trigger","z":"58cb85a8.82904c","name":"","op1":"","op2":"","op1type":"pay","op2type":"nul","duration":"10","extend":false,"units":"s","reset":"","bytopic":"topic","topic":"_msgid","outputs":1,"x":690,"y":200,"wires":[["3b2238f8.71f6c8"]]},{"id":"3802c45b.84121c","type":"function","z":"58cb85a8.82904c","name":"Target Process","func":"// Wait for a specified time period, then send a message.\n// Must preserve incoming message id.\nvar wait = msg.payload;\nsetTimeout(function() {\n msg.payload = \"done: \"+wait+\"s\";\n node.send(msg);\n}, wait*1000);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":120,"wires":[["7096b59a.c265fc"]]},{"id":"a3c01d51.86cbb","type":"change","z":"58cb85a8.82904c","name":"Set timeout flag","rules":[{"t":"set","p":"payload","pt":"msg","to":"timeout","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":240,"wires":[["7096b59a.c265fc"]]},{"id":"ae217597.bedf88","type":"inject","z":"58cb85a8.82904c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":150,"y":240,"wires":[["69b526f1.347808"]]},{"id":"dc6f5bbe.dc8bd8","type":"comment","z":"58cb85a8.82904c","name":"↓ target process","info":"","x":500,"y":80,"wires":[]},{"id":"fe41a803.a14158","type":"comment","z":"58cb85a8.82904c","name":"↓ send second message after specified time","info":"","x":430,"y":160,"wires":[]},{"id":"fbb2dff0.0bacb","type":"comment","z":"58cb85a8.82904c","name":"↓ pass first message with same ID","info":"","x":760,"y":160,"wires":[]}]