I have some flows that end up being executed more than once at the same time, due to overlapping triggers or invocation from other flows. For some of those I don't want them to execute more than once simultaneously. How can I "lock" a flow so that it's guaranteed that if it is executed more than once at the same time, only the first execution continues and all others exit?
I've tried a few things but I always end up with race conditions or other problems.
Restricting Multiple Flow Executions
Moderator: Martin
Re: Restricting Multiple Flow Executions
It's not nativelly possible yet but as far as I know, Martin's working on native support for this. However, this workaround should work in your situation:
Right after the trigger, add ACTION: SET FLOW STATE; DISABLE and then continue your flow regularly. Then add ACTION: SET FLOW STATE; ENABLE, as a last action. This prevents the flow triggering while it's running.
Right after the trigger, add ACTION: SET FLOW STATE; DISABLE and then continue your flow regularly. Then add ACTION: SET FLOW STATE; ENABLE, as a last action. This prevents the flow triggering while it's running.
Re: Restricting Multiple Flow Executions
That's correct, there will be new options in the next version of Automagic to handle such cases (available in the EAP-version, not tested very well yet).
When editing a flow, select menu->Options and select either 'Skip...', 'Wait...' or 'Stop the currently executing instance and execute afterwards'.
When editing a flow, select menu->Options and select either 'Skip...', 'Wait...' or 'Stop the currently executing instance and execute afterwards'.
Re: Restricting Multiple Flow Executions
Hey, why you don't want to use condition Flow Executing? It provides a variable flow_execution_contexts.
Here is solution:
First after trigger goes condition Flow Executing with the same flow executing. It is understood that it always be true.
Next comes condition Expression flow_execution_contexts == 1. Flow continues execution only if true.
By the way, using Disable/Enable flow you can forgot enable it in all cases. And you can't easily stop flow, you should enable it again manually.
Here is solution:
First after trigger goes condition Flow Executing with the same flow executing. It is understood that it always be true.
Next comes condition Expression flow_execution_contexts == 1. Flow continues execution only if true.
By the way, using Disable/Enable flow you can forgot enable it in all cases. And you can't easily stop flow, you should enable it again manually.
Sorry for bad english, my native is russian.
Re: Restricting Multiple Flow Executions
I'm running tests using both enable/disable and Flow Executing. So far it seems that both are fine as long as the only concern is the flow being executed simultaneously (or nearly simultaneously) by its own triggers. Things seem to get complicated, though, when there is the possibility that the flow can also be executed by another flow. The results on that are not yet in.