Skip to content

Commit 3da1dbf

Browse files
🩹 [Patch]: Add retry on Install-PSResource (#27)
## Description This pull request includes a change to the `scripts/main.ps1` introducing a retry mechanism for the `Install-PSResource` command to handle intermittent failures more gracefully. Improvements to installation process: * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011R23-R37): Added retry logic with a maximum of 5 attempts and a 10-second delay between attempts to the `Install-PSResource` command. This change helps ensure that temporary issues do not cause the entire installation process to fail. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 22f292b commit 3da1dbf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scripts/main.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@ $requiredModules.GetEnumerator() | Sort-Object | ForEach-Object {
2020
$name = $_.Key
2121
$settings = $_.Value
2222
LogGroup "Installing prerequisite: [$name]" {
23-
Install-PSResource -Name $name -TrustRepository -Repository PSGallery @settings
24-
Write-Verbose (Get-PSResource -Name $name | Select-Object * | Out-String)
25-
Write-Verbose (Get-Command -Module $name | Out-String)
23+
$Count = 5
24+
$Delay = 10
25+
for ($i = 1; $i -le $Count; $i++) {
26+
try {
27+
Install-PSResource -Name $name -TrustRepository -Repository PSGallery @settings
28+
break
29+
} catch {
30+
if ($i -eq $Count) {
31+
throw $_
32+
}
33+
Start-Sleep -Seconds $Delay
34+
}
35+
}
36+
Write-Host "Installed module: [$name]"
37+
Write-Host (Get-PSResource -Name $name | Select-Object * | Out-String)
38+
39+
Write-Host "Module commands:"
40+
Write-Host (Get-Command -Module $name | Out-String)
2641
}
2742
}
2843

0 commit comments

Comments
 (0)