File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 11# Copyright (c) Microsoft Corporation. All rights reserved.
22# Licensed under the MIT License.
33
4+ function Invoke-WithRetry {
5+ param (
6+ [Parameter (Mandatory = $true )]
7+ [scriptblock ]$ScriptBlock ,
8+
9+ [Parameter (Mandatory = $false )]
10+ [int ]$MaxRetries = 5 ,
11+
12+ [Parameter (Mandatory = $false )]
13+ [int ]$InitialDelayMs = 100 ,
14+
15+ [Parameter (Mandatory = $false )]
16+ [string ]$OperationName = " Operation"
17+ )
18+
19+ for ($attempt = 1 ; $attempt -le $MaxRetries ; $attempt ++ ) {
20+ try {
21+ return & $ScriptBlock
22+ }
23+ catch {
24+ if ($attempt -eq $MaxRetries ) {
25+ Write-Error " $OperationName failed after $MaxRetries attempts. Last error: $_ "
26+ throw
27+ }
28+
29+ $delayMs = $InitialDelayMs * [Math ]::Pow(2 , $attempt - 1 )
30+ Write-Warning " $OperationName failed (attempt $attempt /$MaxRetries ). Retrying in $delayMs ms. Error: $_ "
31+ Start-Sleep - Milliseconds $delayMs
32+ }
33+ }
34+ }
35+
436function Set-CSProjValues (
537 [parameter (Mandatory = $true )][string ] $ModuleCsProj ,
638 [parameter (Mandatory = $true )][string ] $ModuleVersion ,
You can’t perform that action at this time.
0 commit comments