Skip to content

Commit 15554dc

Browse files
committed
Use Invoke-CommandWithRetry
1 parent b0d5fa4 commit 15554dc

1 file changed

Lines changed: 4 additions & 21 deletions

File tree

Actions/DownloadProjectDependencies/DownloadProjectDependencies.Action.ps1

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,10 @@ function Get-AppFileFromUrl {
4747
OutputDebug -message "Overwriting existing file '$sanitizedFileName'. Multiple dependencies may resolve to the same filename."
4848
}
4949

50-
# Download with retry logic (compatible with PS5 and PS7)
51-
$maxRetries = 3
52-
$retryIntervalSec = 5
53-
$retryCount = 0
54-
$success = $false
55-
while (-not $success -and $retryCount -lt $maxRetries) {
56-
try {
57-
Invoke-WebRequest -Method GET -UseBasicParsing -Uri $Url -OutFile $appFile | Out-Null
58-
$success = $true
59-
}
60-
catch {
61-
$retryCount++
62-
if ($retryCount -lt $maxRetries) {
63-
Write-Host "Download failed, retrying in $retryIntervalSec seconds... (Attempt $retryCount of $maxRetries)"
64-
Start-Sleep -Seconds $retryIntervalSec
65-
}
66-
else {
67-
throw $_
68-
}
69-
}
70-
}
50+
# Download with retry logic
51+
Invoke-CommandWithRetry -ScriptBlock {
52+
Invoke-WebRequest -Method GET -UseBasicParsing -Uri $Url -OutFile $appFile | Out-Null
53+
} -RetryCount 3 -FirstDelay 5 -MaxWaitBetweenRetries 10
7154

7255
return $appFile
7356
}

0 commit comments

Comments
 (0)