diff options
Diffstat (limited to 'coin/provisioning/common/windows/helpers.ps1')
-rw-r--r-- | coin/provisioning/common/windows/helpers.ps1 | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index ba35f6b5..100f14ae 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -204,6 +204,38 @@ function Get-Proxy { return (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').proxyServer } +function Retry{ + <# + usage: + Retry{CODE} + Retry{CODE} <num of retries> <delay_s> + #delay is in seconds + #> + Param( + [Parameter(mandatory=$true)] + [scriptblock]$command, + [int][ValidateRange(1, 20)]$retry = 5, + [int][ValidateRange(1, 60)]$delay_s = 5 + ) + $success=$false + $retry_count=0 + do{ + try { + Invoke-Command -ScriptBlock $command + $success=$true + } + catch { + $retry_count++ + Write-Host "Error: $_, try: $retry_count, retrying in $delay_s seconds" + Start-Sleep -Seconds $delay_s + } + } until ($success -or $retry+1 -le $retry_count) + + if (-not $success) { + Throw("Failed to run command successfully in $retry_count tries") + } +} + function Remove { Param ( |