Can I Stop a running flow?

Hello,

So, I have a flow in Node-Red that can take up to 40 minutes to finish. I want to have an input_boolean to just stop the flow wherever it is. The flow consists in various delays and things.

Is there any smart and easy solution to accomplish that?

I’d like to know as well. Tried googling it but to no avail. I also tried to find out if I can make a flow run once at a time, but didn’t find out anything either.

So I tried to mimic it using globals and checking every step, but it’s incredibly messy and so error prone I gave up and wrote the YAML for it. @Kermit perhaps you could shed some light here?

As far as I know there’s no kill switch to stop an entire flow.

If your flows are pausing on delay, trigger and some other timer node. Most of them accept a reset message. So a possible solution might be an event-state for the input_boolean to a change node to set msg.reset and have that connected to each timer type node.

This is really dependent on how your flow operates but might work for some use cases.

You could set a global var on the start of the flow, for example ‘running’=1

then at various points in the flow you could check that ‘running’==1, and only proceed if ‘running’==1

You could also have a simple trigger/button/other flow to set ‘running’=0 which should stop the flow.

Maybe not the best way to do this but I’ve done it in the past and it works for me. :slight_smile:

Is this still a no-go? Stopping a running flow? Since there were lots of updates recently in nodered.

I envision something like a “group-connected” node inputting a “reset” to stop the entire flow. Thus group the entire flow and connect a reset node tot that group…?

Use case: I have an alarm flow executing several things, depending on the state of the previous. This flow can take minutes. But sometimes rhe flow gets triggered in error/mistake and I want to have kill switch wherever the flow is.

Have you looked at the gate node?

I know the gate node. But if a flow has e.g. 20 nodes I need 19 gate nodes…? Not feasible imho. Or do I misunderstand?

No. The flow has to go through nodes. You could use a function note to make your own flow switch by looking at a master variable. If you want the flow to stop, just change the flow.msg to null. Then drop a copy of that node into any flow you want to be able to abort.

Put the flow an a separate tab and you can use this to disable the entire tab. I don’t know that it will reset all delays and timers when it’s re enabled so you’ll need to test it .

[{"id":"3dc73e50.d81c9a","type":"inject","z":"4b82b0cc.556d58","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Test","payload":"true","payloadType":"bool","x":160,"y":200,"wires":[["5f57da6d.0f5b64"]]},{"id":"dd42ff7.cd1438","type":"http request","z":"4b82b0cc.556d58","name":"Get single flow","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://localhost:1880/flow/{{flowId}}","tls":"","persist":false,"proxy":"","authType":"basic","senderr":false,"x":1000,"y":200,"wires":[["6e4f731e.abe73c"]]},{"id":"b9a36067.e23358","type":"debug","z":"4b82b0cc.556d58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1610,"y":200,"wires":[]},{"id":"6e4f731e.abe73c","type":"change","z":"4b82b0cc.556d58","name":"","rules":[{"t":"set","p":"payload.disabled","pt":"msg","to":"flowStatus","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":200,"wires":[["c7dc25cd.221b18"]]},{"id":"42cba935.33793","type":"inject","z":"4b82b0cc.556d58","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Test","payload":"false","payloadType":"bool","x":160,"y":320,"wires":[["5f57da6d.0f5b64"]]},{"id":"5f57da6d.0f5b64","type":"change","z":"4b82b0cc.556d58","name":"","rules":[{"t":"set","p":"flowStatus","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":200,"wires":[["c435d2e3.28e67"]]},{"id":"c7dc25cd.221b18","type":"http request","z":"4b82b0cc.556d58","name":"Update flow","method":"PUT","ret":"obj","paytoqs":"ignore","url":"http://localhost:1880/flow/{{payload.id}}","tls":"","persist":false,"proxy":"","authType":"basic","senderr":false,"x":1430,"y":200,"wires":[["b9a36067.e23358"]]},{"id":"c435d2e3.28e67","type":"http request","z":"4b82b0cc.556d58","name":"Get flows","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://localhost:1880/flows","tls":"","persist":false,"proxy":"","authType":"basic","senderr":false,"x":580,"y":200,"wires":[["13d6bb95.3ba83c"]]},{"id":"13d6bb95.3ba83c","type":"change","z":"4b82b0cc.556d58","name":"get flowId by name","rules":[{"t":"set","p":"flowId","pt":"msg","to":"*[type = 'tab' and label = $$.topic].id","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":200,"wires":[["dd42ff7.cd1438"]]},{"id":"1384c0a8.e3b88f","type":"comment","z":"4b82b0cc.556d58","name":"Enable flow","info":"","x":150,"y":280,"wires":[]},{"id":"abc9854d.c17598","type":"comment","z":"4b82b0cc.556d58","name":"Disable flow","info":"","x":150,"y":160,"wires":[]},{"id":"56008fd8.ad753","type":"comment","z":"4b82b0cc.556d58","name":"This will enable or disable a flow (tab)  The topic should be the flow name.","info":"","x":340,"y":80,"wires":[]},{"id":"432cbfc7.8cef6","type":"inject","z":"4b82b0cc.556d58","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"My Flow","payload":"true","payloadType":"bool","x":170,"y":460,"wires":[["5f57da6d.0f5b64"]]},{"id":"c8eb6499.0a599","type":"inject","z":"4b82b0cc.556d58","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"My Flow","payload":"false","payloadType":"bool","x":170,"y":580,"wires":[["5f57da6d.0f5b64"]]},{"id":"7bcfd22b.9aa0b4","type":"comment","z":"4b82b0cc.556d58","name":"Enable flow","info":"","x":150,"y":540,"wires":[]},{"id":"3145edc5.e295d2","type":"comment","z":"4b82b0cc.556d58","name":"Disable flow","info":"","x":150,"y":420,"wires":[]}]

Tried this, but I keep getting:

Tried to change localhost to ip adress (which listens on por 1880) and tried to disabele authentication which I dont use internally. Any idea?

In the inject node, the topic should be the name of the flow you are trying to stop. Capitalization matters. The http get/put nodes need to be configured with your credentials as well. edit: even if you don’t use https.