Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JitterUp ¶
JitterUp adds random jitter to the duration.
This adds or subtracts time from the duration within a given jitter fraction. For example for 10s and jitter 0.1, it will return a time within [9s, 11s])
func Retry ¶
func Retry(opts ...Option) easyhttp.Interceptor
Types ¶
type BackoffFunc ¶
BackoffFunc denotes a family of functions that control the backoff duration between call retries.
They are called with an identifier of the attempt, and should return a time the system client should hold off for. If the time returned is longer than the `context.Context.Deadline` of the request the deadline of the request takes precedence and the wait will be interrupted before proceeding with the next iteration.
func BackoffExponential ¶
func BackoffExponential(scalar time.Duration) BackoffFunc
BackoffExponential produces increasing intervals for each attempt.
The scalar is multiplied times 2 raised to the current attempt. So the first retry with a scalar of 100ms is 100ms, while the 5th attempt would be 1.6s.
func BackoffExponentialWithJitter ¶
func BackoffExponentialWithJitter(scalar time.Duration, jitterFraction float64) BackoffFunc
BackoffExponentialWithJitter creates an exponential backoff like BackoffExponential does, but adds jitter.
func BackoffLinear ¶
func BackoffLinear(waitBetween time.Duration) BackoffFunc
BackoffLinear is very simple: it waits for a fixed period of time between calls.
func BackoffLinearWithJitter ¶
func BackoffLinearWithJitter(waitBetween time.Duration, jitterFraction float64) BackoffFunc
BackoffLinearWithJitter waits a set period of time, allowing for jitter (fractional adjustment).
For example waitBetween=1s and jitter=0.10 can generate waits between 900ms and 1100ms.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
func Disable ¶
func Disable() Option
Disable disables the retry behaviour on this call, or this interceptor.
Its semantically the same to `WithMaxAttempts`
func WithBackoff ¶
func WithBackoff(bf BackoffFunc) Option
WithBackoff sets the `BackoffFunc` used to control time between retries.
func WithMaxAttempts ¶
WithMaxAttempts sets the maximum number of retries on this call, or this interceptor.
func WithRetryPolicy ¶
func WithRetryPolicy(policyByError RetryWithError, policyByStatusCode RetryWithStatusCode) Option
WithRetryPolicy sets retry policy which decides if a request should be retried.
func WithTimeout ¶
WithTimeout sets the timeout of each HTTP request
type RetryWithError ¶
RetryWithError whether the request should be retried based on error
type RetryWithStatusCode ¶
RetryWithStatusCode whether the request should be retried based on statusCode