Best way to prevent concurrent execution of a microflow (or queue execution) for a single user?

Hello All!   I have a scenario where a DS microflow uses a sub microflow to gain objects to be returned in the containing DS microflow. I have it broken out like this because there is another DS microflow that uses the same sub microflow on the same page (these two DS microflows do slightly different data filtering on the list returned from the sub flow).    the sub flow uses a rest call to create NP objects and attach them to a containing entity, the rest call is only hit if there is no set of NP objects already created/attached.    I’m running into the issue where this subflow can be hit twice from two separate DS flows, and create duplicate records because one instance does not complete before the second instance (If they complete non-concurrently, the second instance would see the already attached NP objects via the first instance and bail before the rest call).    Is there a nice way to prevent or even queue the second instance if there is a currently executing instance that hasn’t completed yet? When disallowing concurrent execution, the user just receives a vague error and would require a repeat of the action that caused the error. This isn’t quite what I’m going for. I did also try task queue, but you cannot queue a microflow that has return objects.    Any and all suggestions would be greatly appreciated!!
1 answers

I would personally call the SUB_microflow fetching the data before opening the page (the DS microflows would retrieve all data over association, then do the filtering). The ‘containing entity’ can be returned or passed to the submicroflow and as a context object to the page. This way you will ensure that the REST call and creation of objects for the data source is only executed once.


Alternatively, the SUB_ microflow could also check if the record already exists, and only create the record if it not exists yet, but you would still have the REST call twice which causes unnecessary additional load on the system...


You could also try adding an enum in the containing entity like “DataRetrievalStatus” (TODO/RETRIEVING/RETRIEVED). If TODO, call the subflow and set to RETRIEVING, the second microflow would then need a loop/wait until all records are RETRIEVED and then to do the filtering. However, this is not very elegant and might still give you concurrency issues (hence I would fetch necessary data before showing the page) 


Note: Disallow concurrent execution would never work, because this would also mean that 2 different users are not allowed to run the microflow simultaneously (as the objects are NPE’s there should never be a conflict between 2 sessions). Using “Disallow concurrent execution” is mostly relevant to prevent duplicate background synchronizations for persistent/global data...