Skip to content

Commit

Permalink
Alter retry handling to increase delay after subsequent retries.
Browse files Browse the repository at this point in the history
  • Loading branch information
homotechsual authored Oct 23, 2023
1 parent 1607e2b commit 60a501d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Public/Invoke-HaloRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function Invoke-HaloRequest {
$RequestHeaders = $null
}
$Retries = 0
$BaseDelay = 5 # Base delay of 5 seconds
$MaxDelay = 60 # Maximum delay of 60 seconds
do {
$Retries++
$Results = try {
Expand All @@ -61,8 +63,9 @@ function Invoke-HaloRequest {
} catch [Microsoft.PowerShell.Commands.HttpResponseException] {
$Success = $False
if ($_.Exception.Response.StatusCode.value__ -eq 429) {
Write-Warning 'The request was throttled, waiting for 5 seconds.'
Start-Sleep -Seconds 5
$WaitTime = [math]::Min($BaseDelay * [math]::Pow(2, $Retries - 1), $MaxDelay)
Write-Warning "The request was throttled, waiting for $WaitTime seconds."
Start-Sleep -Seconds $WaitTime
continue
} else {
throw $_
Expand Down

0 comments on commit 60a501d

Please sign in to comment.