Skip to content

Commit

Permalink
retry: make max retries configurable (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwanthgoli authored Oct 28, 2024
1 parent 22d521d commit df2a8f5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Client struct {
healthStatus int32

trailingHeaderSupport bool
maxRetries int
}

// Options for New method
Expand All @@ -123,6 +124,10 @@ type Options struct {
// Custom hash routines. Leave nil to use standard.
CustomMD5 func() md5simd.Hasher
CustomSHA256 func() md5simd.Hasher

// Number of times a request is retried. Defaults to 10 retries if this option is not configured.
// Set to 1 to disable retries.
MaxRetries int
}

// Global constants.
Expand Down Expand Up @@ -278,6 +283,11 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
// healthcheck is not initialized
clnt.healthStatus = unknown

clnt.maxRetries = MaxRetry
if opts.MaxRetries > 0 {
clnt.maxRetries = opts.MaxRetries
}

// Return.
return clnt, nil
}
Expand Down Expand Up @@ -590,9 +600,9 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ
return nil, errors.New(c.endpointURL.String() + " is offline.")
}

var retryable bool // Indicates if request can be retried.
var bodySeeker io.Seeker // Extracted seeker from io.Reader.
reqRetry := MaxRetry // Indicates how many times we can retry the request
var retryable bool // Indicates if request can be retried.
var bodySeeker io.Seeker // Extracted seeker from io.Reader.
var reqRetry = c.maxRetries // Indicates how many times we can retry the request

if metadata.contentBody != nil {
// Check if body is seekable then it is retryable.
Expand Down

0 comments on commit df2a8f5

Please sign in to comment.