retry

package
v0.0.0-...-dc5a3c1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a wrapper for a HTTP client that adds a retry logic to manage temporary failures

func NewClient

func NewClient(c *http.Client, strategy Strategy, maxRetries int) *Client

NewClient returns the client passed as input wrapped with a retry logic strategy is the Strategy used to get a backoff time before the next retry maxRetries is the maximum number of retries before returning a failure

func NewDefaultClient

func NewDefaultClient(strategy Strategy, maxRetries int) *Client

NewDefaultClient returns the default http package client wrapped with a retry logic strategy is the Strategy used to get a backoff time before the next retry maxRetries is the maximum number of retries before returning a failure

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends the HTTP request req, returning its response. If the request fail, it waits a backoff time taken from the strategy set and try again

type Constant

type Constant struct {
	// Quantum is the basic unit of duration for the algorithm
	Quantum time.Duration
}

Constant implements the constant backoff algorithm

func (Constant) BackOff

func (c Constant) BackOff(_ int) time.Duration

BackOff satisfies the Strategy interface for the Constant type it gets the current retry number to return the associated constant backoff duration

type Exponential

type Exponential struct {
	// Quantum is the basic unit of duration for the algorithm
	Quantum time.Duration
}

Exponential implements the exponential backoff algorithm

func (Exponential) BackOff

func (e Exponential) BackOff(n int) time.Duration

BackOff satisfies the Strategy interface for the Exponential type it gets the current retry number to return the associated exponential backoff duration

type JitteredConstant

type JitteredConstant struct {
	Constant
}

JitteredConstant implements the constant backoff algorithm with a +/- 33% jitter

func (JitteredConstant) BackOff

func (jc JitteredConstant) BackOff(n int) time.Duration

BackOff satisfies the Strategy interface for the JitteredConstant type it gets the current retry number to return the associated jittered constant backoff duration

type JitteredExponential

type JitteredExponential struct {
	Exponential
}

JitteredExponential implements the exponential backoff algorithm with a +/- 33% jitter

func (JitteredExponential) BackOff

func (je JitteredExponential) BackOff(n int) time.Duration

BackOff satisfies the Strategy interface for the Exponential type it gets the current retry number to return the associated exponential backoff duration

type JitteredLinear

type JitteredLinear struct {
	Linear
}

JitteredLinear implements the linear backoff algorithm with a +/- 33% jitter

func (JitteredLinear) BackOff

func (jl JitteredLinear) BackOff(n int) time.Duration

BackOff satisfies the Strategy interface for the JitteredLinear type it gets the current retry number to return the associated jittered linear backoff duration

type Linear

type Linear struct {
	// Quantum is the basic unit of duration for the algorithm
	Quantum time.Duration
}

Linear implements the linear backoff algorithm

func (Linear) BackOff

func (l Linear) BackOff(n int) time.Duration

BackOff satisfies the Strategy interface for the Linear type it gets the current retry number to return the associated linear backoff duration

type Strategy

type Strategy interface {
	BackOff(n int) time.Duration
}

Strategy is an interface that wraps the BackOff method

Jump to

Keyboard shortcuts

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