Skip to content

Commit 9554986

Browse files
authored
Merge pull request #175 from Charliekenney23/feat/retry-customization
allow customizing retry count and retry wait time
2 parents f260595 + d72edc7 commit 9554986

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,31 @@ func (c *Client) addRetryConditional(retryConditional RetryConditional) *Client
184184
return c
185185
}
186186

187+
// SetRetryMaxWaitTime sets the maximum delay before retrying a request.
187188
func (c *Client) SetRetryMaxWaitTime(max time.Duration) *Client {
188189
c.resty.SetRetryMaxWaitTime(max)
189190
return c
190191
}
191192

193+
// SetRetryWaitTime sets the default (minimum) delay before retrying a request.
194+
func (c *Client) SetRetryWaitTime(min time.Duration) *Client {
195+
c.resty.SetRetryWaitTime(min)
196+
return c
197+
}
198+
199+
// SetRetryAfter sets the callback function to be invoked with a failed request
200+
// to determine wben it should be retried.
201+
func (c *Client) SetRetryAfter(callback RetryAfter) *Client {
202+
c.resty.SetRetryAfter(resty.RetryAfterFunc(callback))
203+
return c
204+
}
205+
206+
// SetRetryCount sets the maximum retry attempts before aborting.
207+
func (c *Client) SetRetryCount(count int) *Client {
208+
c.resty.SetRetryCount(count)
209+
return c
210+
}
211+
192212
// SetPollDelay sets the number of milliseconds to wait between events or status polls.
193213
// Affects all WaitFor* functions and retries.
194214
func (c *Client) SetPollDelay(delay time.Duration) *Client {

retries.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const retryAfterHeaderName = "Retry-After"
1414
// type RetryConditional func(r *resty.Response) (shouldRetry bool)
1515
type RetryConditional resty.RetryConditionFunc
1616

17+
// type RetryAfter func(c *resty.Client, r *resty.Response) (time.Duration, error)
18+
type RetryAfter resty.RetryAfterFunc
19+
1720
// Configures resty to
1821
// lock until enough time has passed to retry the request as determined by the Retry-After response header.
1922
// If the Retry-After header is not set, we fall back to value of SetPollDelay.

0 commit comments

Comments
 (0)