Skip to content

Commit

Permalink
retry: make max retries configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwanth Goli <[email protected]>
  • Loading branch information
ashwanthgoli committed Oct 23, 2024
1 parent 9f2a600 commit f4d0a5e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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,8 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
// healthcheck is not initialized
clnt.healthStatus = unknown

clnt.maxRetries = opts.MaxRetries

// Return.
return clnt, nil
}
Expand Down Expand Up @@ -592,7 +599,11 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ

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

reqRetry := MaxRetry // Indicates how many times we can retry the request
if c.maxRetries > 0 {
reqRetry = c.maxRetries
}

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

0 comments on commit f4d0a5e

Please sign in to comment.