Task chaining
Automations make it easy to use events and actions to trigger other events and actions. This is called task chaining. A task chain is a set of tasks that are executed in an automation, either in parallel or one after the other. This tutorial walks you through an end-to-end example in steps of increasing complexity that shows you how to build a task chain. The goal of this automation is to trigger app reloads for multiple apps in your tenant by chaining multiple reloads together.
Create a simple reload automation
Start by creating an automation that triggers an app reload.
-
From the Block library on the left side of the automation canvas, select the Qlik Cloud Services connector.
-
Drag the Do reload block onto the canvas and attach it to the start block.
-
In the App ID input field for the Do reload block, enter the App ID for the app you want to reload.
信息注释You can use the lookup function in the App ID field to find the App ID.
-
Click Run.
-
Verify in the block output that you see
status: SUCCEEDED
. This indicates that the reload was successful.
Reload run modes
In the steps above, you did not specify the run mode for the Do reload block. However, when creating task chains, this input is important. You have two options: Wait for reload to complete and Start reload and continue. That is, run the reloads one after the other or run them in parallel.
The default setting is Wait for reload to complete, which is a run mode where the automation waits for the current reload to return the status before proceeding to the next block.
The alternative setting is Start reload and continue, which is a run mode where the reload is triggered, a reload ID is returned, and the automation moves to the next block. If there are multiple Do reload blocks, they are triggered before waiting for the preceding reload to return a status.
Use the reload ID in the block Get reload record block to get the reload status.
Create a reload task chain
Continuing with the same reload automation from above, add another Do reload block to create a task chain to reload two apps.
-
Set the run mode for the first Do reload block to Wait for reload to complete. This way, the second Do reload block will only execute once the first Do reload block is finished.
-
Drag a second Do reload block onto the canvas and attach it to the existing Do reload block.
-
Click Run.
-
Verify in the block output that you see
status: SUCCEEDED
for both reload blocks. This indicates that the reloads were successful.
Add a condition to the task chain
In the task chain above, both reloads are triggered regardless of the reload status. Add a condition to trigger the second reload only if the first reload is successful.
-
Remove the second Do reload block from the automation by dragging to another place on the canvas.
-
From the block selector pane, drag a basic condition block onto the canvas and attach it below the first Do reload block.
-
In the Inputs field for the condition block, field map the status of the app reload from the Do reload block and set the condition statement to
equals
and type SUCCEEDED in the Value field. -
Re-add the second Do reload block to the YES branch of the condition. This means that if the condition is
true
, the second Do reload block is executed.提示注释Add block comments so you can see what each block does without opening it.
-
Click Run to see the output.
Run reloads in parallel
Next, add multiple Do reload blocks to your automation. For each Do reload block, set the run mode to Start reload and continue.
-
Move the condition block to the side so you are left with the start block and a single Do reload block.
-
Take the second Do reload block from inside the condition and reattach it below the first Do reload block.
-
Set the run mode for each Do reload block to Start reload and continue.
The automation looks like this, with both reloads running in parallel:
-
Below the second Do reload block, add a Wait for reloads to complete block.
-
In the Reload IDs field, add the reload ID from the first two Do reload blocks, separated by a comma.
The raw input looks like this:
{$.DoReload.id},{$.DoReload2.id}
.提示注释Make sure to use the reload ID and not the app ID.
-
Add another Do reload block and configure it to reload another app.
Add a loop to the task chain
In this example, use a loop block to loop over all the apps in your tenant and to trigger a reload for each one.
-
Move all of the blocks below the start block to the side.
-
Add a List apps block to the start block. This block is a loop block.
-
Click Test run on the block to get the IDs you need for the next block.
-
Inside the loop, add a Do reload block.
-
In the App ID field of the Do reload block, map the App ID obtained from the from the List apps block. Set the Run Mode to Start reload and continue.
The raw format looks like this:{$.listApps.item.id}
. The input to the Do reload block will loop through the app IDs in the list until it reaches the end of the list.
If you don't have reload permission for all apps on the tenant, specify a space ID to which you have reload permission in the List Apps block. Alternatively, you can set the On error field to Ignore or Warning.
Add a loop and condition to the task chain
Finally, add a condition inside the loop from the previous example.
-
Add a basic Condition block inside the loop, above the Do reload block.
-
Set the condition to reload apps only if the app name contains the word production.
-
Add the Do reload block to the YES branch of the condition.
-
In the App ID field for the Do reload block, map the App ID obtained from the List Apps block. Set the Run Mode to Start reload and continue.
The final result is an automation that loops through all of the apps on your tenant, and if the app name contains the word production, the app reload is triggered. Modify this automation to build your own custom task chain.