Loading...

Azure Automation modular runbooks: calling as many instances of a child runbook as desired and wait for job execution

Reply A+ A-


In this post I will show you how to build intelligent modular runbook allowing you to call as many instances of a child runbook you want by adding a logic to wait if there are too much execution.


Calling child runbook

In the previous poste, here, I explained how to call a child runbook from a main rubook.

For that we used the Start-AzAutomationRunbook cmdlet, to call the child runbook.


Now let's go further by calling the child runbook as many times as we want.


The solution

To build this intelligent modular runbook solution we need a main runbook and a child runbook.

The main runbook is used to call the child runbook, as before.

I have a loop that will be used to run he child runbook for different data.

The main runbook will wait for the current job execution before calling again the child runbook.


Waiting for current job execution

This is the main part of the logic.

Indeed here we want to check if the current job is finished or not. 

For that we will use the following function using the Get-AzAutomationJob cmdlet.


Calling the child runbook and wait

In the following example I have an array as below:


The main runbook will execute the child runbook for every item in the array (here 5) and will pass as parameter value from the array.

The logic in our script will run 5 runbooks at the same time and if there are more it will wait.

Here is the code for that:


Get the script

Click on the below GitHub picture to downloads both main and child runbooks.


Solution in action

Now let's call the child runbook.

Here is the main runbook I used:


Here is the child runbook I used:


The main runbook will execute 5 instances of the child runbook.

In the runbook we defined 5 instances at the same time:

On the main runbook,  click on the Start button:


The main runbook is starting.

Then, we can see 5 instances of the Child runbook:


The output for each instance displays what we added as parameter:





Now let's add 10 instances to run instead of 5:

Let's run again the main runbook.

Then, we can see 5 instances of the Child runbook:

Then, once the 5 instances are finished, the other group of 5 starts:

Start-AzAutomationRunbook 6170904890317228452

Enregistrer un commentaire

Accueil item

Award

Sponsors

Learn KQL in one month

You want to support me ?

Mes articles en français

Books in French


Stats