Skip to content

Commit

Permalink
Merge pull request #121 from Skwie/RetryCommand-fix-scriptblock
Browse files Browse the repository at this point in the history
Fix scriptblock conversion to string
  • Loading branch information
Skwie authored Dec 16, 2024
2 parents 50cf19e + 853070a commit 27d1061
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions WAFAzCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,28 @@ function New-RetryCommand
param (
[Parameter(Mandatory=$true)][string]$command,
[Parameter(Mandatory=$true)][hashtable]$arguments,
[Parameter(Mandatory=$false)][int]$maxretries = 5,
[Parameter(Mandatory=$false)][int]$maxRetries = 5,
[Parameter(Mandatory=$false)][int]$delay = 2
)

$arguments.ErrorAction = "Stop"

$retrycount = 0
$retryCount = 0
$done = $false
$scriptBlock = [ScriptBlock]::Create($command)

while (-not $done -and $retrycount -lt $maxretries) {
while (-not $done -and $retryCount -lt $maxRetries) {
try {
& $command @arguments
& $scriptBlock @arguments
$done = $true
}
catch {
if ($retrycount -ge $maxretries) {
Write-Error ("Command $($command) failed the maximum number of $($maxretries) times.") -ErrorAction Continue
if ($retryCount -ge $maxRetries) {
Write-Error ("Command $($command) failed the maximum number of $($maxRetries) times.") -ErrorAction Continue
} else {
Write-Verbose ("Command $($command) did not complete successfully. Retrying in $($delay) seconds.")
Start-Sleep $delay
$retrycount++
$retryCount++
}
}
}
Expand Down

0 comments on commit 27d1061

Please sign in to comment.