Files
syno-scripts/Powershell/Shutdown_V3/Modules/Retry.md
T

24 lines
395 B
Markdown
Executable File

function Invoke-Retry {
param(
[scriptblock]$Action,
[int]$Retries = 3,
[int]$DelaySeconds = 5,
[string]$Name = "Operation"
)
```
for ($i = 1; $i -le $Retries; $i++) {
try {
return & $Action
}
catch {
Write-Log "$Name failed ($i/$Retries): $($_.Exception.Message)" -Level WARN
if ($i -eq $Retries) { throw }
Start-Sleep $DelaySeconds
}
}
```
}