Hi, I'm using the below powershell script to execute child runbook from another runbook and run into timeout errors. How do I work around this issue.
workflow Start-AutomationChildRunbook
{
[OutputType([object])]
param (
[Parameter(Mandatory=$true)]
[string]
$ChildRunbookName,
[Parameter(Mandatory=$false)]
[hashtable]
$ChildRunbookInputParams,
[Parameter(Mandatory=$true)]
[PSCredential]
$AzureOrgIdCredential,
[Parameter(Mandatory=$true)]
[string]
$AzureSubscriptionName
[Parameter(Mandatory=$true)]
[string]
$AutomationAccountName,
[Parameter(Mandatory=$false)]
[boolean]
$WaitForJobCompletion = $false,
[Parameter(Mandatory=$false)]
[boolean]
$ReturnJobOutput = $false,
[Parameter(Mandatory=$false)]
[int]
$JobPollingIntervalInSeconds = 10,
[Parameter(Mandatory=$false)]
[int]
$JobPollingTimeoutInSeconds = 600
)
# Determine if parameter values are incompatible
if(!$WaitForJobCompletion -and $ReturnJobOutput) {
$msg = "The parameters WaitForJobCompletion and ReturnJobOutput must both "
$msg += "be true if you want job output returned."
throw ($msg)
}
# Connect to Azure so that this runbook can call the Azure cmdlets
Add-AzureAccount -Credential $AzureOrgIdCredential | Write-Verbose
# Select the Azure subscription we will be working against
Select-AzureSubscription -SubscriptionName $AzureSubscriptionName | Write-Verbose
# Assure not null for this param
if ($ChildRunbookInputParams -eq $null) { $ChildRunbookInputParams = @{} }
# Start the child runbook and get the job returned
$job = Start-AzureAutomationRunbook `
-Name $ChildRunbookName `
-Parameters $ChildRunbookInputParams `
-AutomationAccountName $AutomationAccountName `
-ErrorAction "Stop"
# Determine if there is a job and if the job output is wanted or not
if ($job -eq $null) {
# No job was created, so throw an exception
throw ("No job was created for runbook: $ChildRunbookName.")
}
else {
# There is a job
# Log the started runbook’s job id for tracking
Write-Verbose "Started runbook: $ChildRunbookName. Job Id: $job.Id"
if (-not $WaitForJobCompletion) {
# Don't wait for the job to finish, just return the job id
Write-Output $job.Id
}
else {
# Monitor the job until finish or timeout limit has been reached
$maxDateTimeout = InlineScript{(Get-Date).AddSeconds($using:JobPollingTimeoutInSeconds)}
$doLoop = $true
while($doLoop) {
Start-Sleep -s $JobPollingIntervalInSeconds
$job = Get-AzureAutomationJob `
-Id $job.Id `
-AutomationAccountName $AutomationAccountName
if ($maxDateTimeout -lt (Get-Date)) {
# timeout limit reached so exception
$msg = "The job for runbook $ChildRunbookName did not "
$msg += "complete within the timeout limit of "
$msg += "$JobPollingTimeoutInSeconds seconds, so polling "
$msg += "for job completion was halted. The job will "
$msg += "continue running, but no job output will be returned."
throw ($msg)
}
$doLoop = (($job.Status -notmatch "Completed") `
-and ($job.Status -notmatch "Failed") `
-and ($job.Status -notmatch "Suspended") `
-and ($job.Status -notmatch "Stopped"))
}
if ($job.Status -match "Completed") {
if ($ReturnJobOutput) {
# Output
$jobout = Get-AzureAutomationJobOutput `
-Id $job.Id `
-AutomationAccountName $AutomationAccountName `
-Stream Output
if ($jobout) {Write-Output $jobout.Text}
# Error
$jobout = Get-AzureAutomationJobOutput `
-Id $job.Id `
-AutomationAccountName $AutomationAccountName `
-Stream Error
if ($jobout) {Write-Error $jobout.Text}
# Warning
$jobout = Get-AzureAutomationJobOutput `
-Id $job.Id `
-AutomationAccountName $AutomationAccountName `
-Stream Warning
if ($jobout) {Write-Warning $jobout.Text}
# Verbose
$jobout = Get-AzureAutomationJobOutput `
-Id $job.Id `
-AutomationAccountName $AutomationAccountName `
-Stream Verbose
if ($jobout) {Write-Verbose $jobout.Text}
}
else {
# Return the job id
Write-Output $job.Id
}
}
else {
# The job did not complete successfully, so throw an exception
$msg = "The child runbook job did not complete successfully."
$msg += " Job Status: " + $job.Status + "."
$msg += " Runbook: " + $ChildRunbookName + "."
$msg += " Job Id: " + $job.Id + "."
$msg += " Job Exception: " + $job.Exception
throw ($msg)
}
}
}
}
Error: The job for runbook did not complete within the timeout limit of 600 seconds, so polling for job completion was halted. The job will continue running, but no job output will be returned.
Code block for error:
if ($maxDateTimeout -lt (Get-Date)) {
# timeout limit reached so exception
$msg = "The job for runbook $ChildRunbookName did not "
$msg += "complete within the timeout limit of "
$msg += "$JobPollingTimeoutInSeconds seconds, so polling "
$msg += "for job completion was halted. The job will "
$msg += "continue running, but no job output will be returned."
throw ($msg)
}
I'm using hybrid worker group for azure automation runbook execution. I was planning to imply batch execution but not sure how to implement it. Any inputs would be helpful. The parent runbook reads data from a text file and in some scenarios the record count run into millions. How would I pass data in chunks of 25,000 records or so let's say.
Thank you