easyhttpretry

package module
v0.0.0-...-7792c53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JitterUp

func JitterUp(duration time.Duration, jitter float64) time.Duration

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

type BackoffFunc func(attempt uint) time.Duration

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

func WithMaxAttempts(maxAttempts uint) Option

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

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout of each HTTP request

type RetryWithError

type RetryWithError func(err error) bool

RetryWithError whether the request should be retried based on error

type RetryWithStatusCode

type RetryWithStatusCode func(statusCode int) bool

RetryWithStatusCode whether the request should be retried based on statusCode

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL