Action timer/wait

I have an automation that calls a handful of others. after all the actions are completed i want to run a final action. i know i can check wait until complete on each action but for speed purposes i want them all to run immediately, not wait for one then the next, etc. is there a way to group all the actions together and say wait for them all to complete then proceed to the last action?

Hi Brent,

You would need to build a type of latch synchronization mechanism.

I don’t think it would be too hard. An approach like this might be suitable by using values written into the database:

  1. The parent automation uses a Lookup Tables “save value” action to initialize a value in the database in the “my account” scope, with data replacement set to “matching key”. The keygroup can be “my_account_latches”, the key can be “latch_name” (pick a name), the valuename can be “count” and the value can be “1”. All this does is to reset the latch from previous runs of the automations.

  2. The forked automations also save a value into the database when they complete their processing using the Lookup Tables “save value” action. The data replacement is “none”. The scope, keygroup, key, and valuename, and value are all the same. What will happen is that an array of “count” entries will be added to the database. This is better than trying to increment a number for the count b/c of race conditions if automations happen to finish at the exact same time. Synchronization is tricky!

  3. Determine the maximum amount of time you want to wait before timing out your latch mechanism. A timeout of some sort is needed to handle the case where a forked automation doesn’t increment the count for some reason. Say you know the forked automations generally complete in 5 minutes so you want a timeout of 15 minutes. Loops in the automation editor are based on array elements. After the parent automation forks the child automations, use the Transform Data “emit fixed number of loop iterations” and emit 15. Then in a loop that iterates on those iterations, use the Lookup Tables “get value” to fetch the count. It should return an array of values as the forked automations complete. Use the Transform Data “count array elements” action to get a count of the array. Use a conditional to check if the count is equal to the number of forked automations +1 (+1 for the initial entry in step 1 above). If yes, use the Break Loop action to halt the loop. If no, use the Date Time “pause for a specified number of seconds” to pause for 60 seconds.

The outer loop will exit either when all forked automations have completed or when roughly 15 minutes have elapsed.

It’s important that all the actions in the forked automations be configured to “continue on error”, otherwise the automations will not execute the latch increment logic at the end of their processing. This doesn’t handle the case of critical errors occurring in the forked automations which will halt them, but the timeout logic will eventually time out the latch loop. If all the forked actions are ones you have built, you could modify their assemblies to not throw any errors at all. Or clone and modify assemblies you didn’t build to do the same.

If you wanted to get fancy, you could probably build all the latch logic into reusable action assemblies.

Let me know if you need further guidance,

Robert

Follow up to this with a similar question…

I have a call that runs a report. the original request returns an ID that i need to call separately to retrieve the report. until the report is ready it returns a status of pending.

is there a way to keep looping and ping every 10 seconds or so? like a conditional loop with the timer to wait? with each run it pings, checks the status, if pending, waits another 10 seconds then retries the prcoess.

edit: this is all within a subassembly if possible

This type of ping loop within an assembly can currently only be done via inline JSP or PHP code, as none of the Loop modules have an ability to test a condition that occurs within the nested item.

FYI the next system release will have built-in support for latched automation executions as I described here. The “execute automation” action will let you define a latch group, then a new “wait for latched automations” action will wait for all those forked child automations to complete their execution before continuing.