Skip to content

Commit

Permalink
Merge pull request #175 from Charliekenney23/feat/retry-customization
Browse files Browse the repository at this point in the history
allow customizing retry count and retry wait time
  • Loading branch information
0xch4z authored Jan 15, 2021
2 parents f260595 + d72edc7 commit 9554986
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,31 @@ func (c *Client) addRetryConditional(retryConditional RetryConditional) *Client
return c
}

// SetRetryMaxWaitTime sets the maximum delay before retrying a request.
func (c *Client) SetRetryMaxWaitTime(max time.Duration) *Client {
c.resty.SetRetryMaxWaitTime(max)
return c
}

// SetRetryWaitTime sets the default (minimum) delay before retrying a request.
func (c *Client) SetRetryWaitTime(min time.Duration) *Client {
c.resty.SetRetryWaitTime(min)
return c
}

// SetRetryAfter sets the callback function to be invoked with a failed request
// to determine wben it should be retried.
func (c *Client) SetRetryAfter(callback RetryAfter) *Client {
c.resty.SetRetryAfter(resty.RetryAfterFunc(callback))
return c
}

// SetRetryCount sets the maximum retry attempts before aborting.
func (c *Client) SetRetryCount(count int) *Client {
c.resty.SetRetryCount(count)
return c
}

// SetPollDelay sets the number of milliseconds to wait between events or status polls.
// Affects all WaitFor* functions and retries.
func (c *Client) SetPollDelay(delay time.Duration) *Client {
Expand Down
3 changes: 3 additions & 0 deletions retries.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const retryAfterHeaderName = "Retry-After"
// type RetryConditional func(r *resty.Response) (shouldRetry bool)
type RetryConditional resty.RetryConditionFunc

// type RetryAfter func(c *resty.Client, r *resty.Response) (time.Duration, error)
type RetryAfter resty.RetryAfterFunc

// Configures resty to
// lock until enough time has passed to retry the request as determined by the Retry-After response header.
// If the Retry-After header is not set, we fall back to value of SetPollDelay.
Expand Down

0 comments on commit 9554986

Please sign in to comment.