Skip to content

Commit

Permalink
add retry for 4xx and 5xx requests
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Dec 10, 2022
1 parent ba65972 commit 8f59509
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions azuremetadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ func (m *AzureMetadata) Init() {
m.restClient.SetHeader("Metadata", "true")
m.restClient.SetHeader("Accept", "application/json")
m.restClient.SetTimeout(*m.Timeout)

// retry
m.restClient.SetRetryCount(5)
m.restClient.SetRetryMaxWaitTime(30 * time.Second)
m.restClient.SetRetryWaitTime(5 * time.Second)
m.restClient.AddRetryCondition(resty.RetryConditionFunc(func(r *resty.Response, err error) bool {
// retry for 4xx and 5xx
return r.StatusCode() >= http.StatusBadRequest
}))
}

func (m *AzureMetadata) FetchScheduledEvents() (*AzureScheduledEventResponse, error) {
Expand Down

0 comments on commit 8f59509

Please sign in to comment.