Creating flows based on node-red events?

Though this has no real code in it, this is (maybe) a better example of what I am trying to say:

[{"id":"e6e5edba.0a4358","type":"function","z":"8bb4de19.f72c88","name":"startup stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2690,"y":3130,"wires":[["2ea75733.23cd38"]]},{"id":"2ea75733.23cd38","type":"function","z":"8bb4de19.f72c88","name":"main stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2840,"y":3130,"wires":[["4decf0aa.7c4248"]]},{"id":"4decf0aa.7c4248","type":"function","z":"8bb4de19.f72c88","name":"end stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2980,"y":3130,"wires":[["904f2553.f7283"]]},{"id":"a5221b63.7698e","type":"comment","z":"8bb4de19.f72c88","name":"This is your existing flow.","info":"","x":2840,"y":3090,"wires":[]},{"id":"7cc29f0d.525948","type":"function","z":"8bb4de19.f72c88","name":"This determins that the flow should be done","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2700,"y":3050,"wires":[["e6e5edba.0a4358"]]},{"id":"14e27688.181e59","type":"function","z":"8bb4de19.f72c88","name":"This wipes all the stored variables (etc)","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":3020,"y":3230,"wires":[["7cc29f0d.525948"]]},{"id":"904f2553.f7283","type":"delay","z":"8bb4de19.f72c88","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":3140,"y":3130,"wires":[["14e27688.181e59"]]},{"id":"b738c446.d813a8","type":"comment","z":"8bb4de19.f72c88","name":"All done and get ready for next time.","info":"","x":3210,"y":3090,"wires":[]}]

Just to show you what I am meaning.

Hope it helps.

And really the wire from the wipe node back to the start node isn't needed.
The start node detects things externally anyway and doesn't need an input (from a node as shown).

Can you understand what I am trying to show you?

1 Like

Zoom out and take a screen shot of the flow (don't post the code) and maybe show what is the input and which is the output.

The built in persistent storage plugin does flush to disk when a close event happens. All nodes get a close event, so they can tidy themselves up, but you can't run a flow based on it. As Nick said there is work in progress to allow more graceful stopping (eg allow a flow to complete before stop etc)