Skip to content

Commit

Permalink
Added RetryConditions option to Request level (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitkg98 committed Sep 16, 2021
1 parent d1979b9 commit 2cae8cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client.go
Expand Up @@ -589,6 +589,9 @@ func (c *Client) SetRetryAfter(callback RetryAfterFunc) *Client {
// AddRetryCondition method adds a retry condition function to array of functions
// that are checked to determine if the request is retried. The request will
// retry if any of the functions return true and error is nil.
//
// Note: These retry conditions are applied on all Request made using this Client.
// For Request specific retry conditions check *Request.AddRetryCondition
func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client {
c.RetryConditions = append(c.RetryConditions, condition)
return c
Expand Down
13 changes: 12 additions & 1 deletion request.go
Expand Up @@ -67,6 +67,7 @@ type Request struct {
clientTrace *clientTrace
multipartFiles []*File
multipartFields []*MultipartField
retryConditions []RetryConditionFunc
}

// Context method returns the Context if its already set in request
Expand Down Expand Up @@ -593,6 +594,16 @@ func (r *Request) SetCookies(rs []*http.Cookie) *Request {
return r
}

// AddRetryCondition method adds a retry condition function to the request's
// array of functions that are checked to determine if the request is retried.
// The request will retry if any of the functions return true and error is nil.
//
// Note: These retry conditions are checked before all retry conditions of the client.
func (r *Request) AddRetryCondition(condition RetryConditionFunc) *Request {
r.retryConditions = append(r.retryConditions, condition)
return r
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// HTTP request tracing
//_______________________________________________________________________
Expand Down Expand Up @@ -763,7 +774,7 @@ func (r *Request) Execute(method, url string) (*Response, error) {
Retries(r.client.RetryCount),
WaitTime(r.client.RetryWaitTime),
MaxWaitTime(r.client.RetryMaxWaitTime),
RetryConditions(r.client.RetryConditions),
RetryConditions(append(r.retryConditions, r.client.RetryConditions...)),
RetryHooks(r.client.RetryHooks),
)

Expand Down

0 comments on commit 2cae8cd

Please sign in to comment.