retry

package
v0.1.243 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit    = 2
	DefaultInterval = 1 * time.Second
	DefaultJitter   = 0.2
)

Default configuration:

Variables

This section is empty.

Functions

This section is empty.

Types

type TransportWrapper

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

TransportWrapper contains the data and logic needed to wrap an HTTP round tripper with another one that adds retry capability.

func (*TransportWrapper) Close

func (w *TransportWrapper) Close() error

Close releases all the resources used by the wrapper.

func (*TransportWrapper) Interval

func (w *TransportWrapper) Interval() time.Duration

Interval returns the initial retry interval.

func (*TransportWrapper) Jitter

func (w *TransportWrapper) Jitter() float64

Jitter returns the retry interval jitter factor.

func (*TransportWrapper) Limit

func (w *TransportWrapper) Limit() int

Limit returns the maximum number of retries.

func (*TransportWrapper) Wrap

func (w *TransportWrapper) Wrap(transport http.RoundTripper) http.RoundTripper

Wrap creates a new round tripper that wraps the given one and implements the retry logic.

type TransportWrapperBuilder

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

TransportWrapperBuilder contains the data and logic needed to create a new retry transport wrapper.

func NewTransportWrapper

func NewTransportWrapper() *TransportWrapperBuilder

NewTransportWrapper creates a new builder that can then be used to configure and create a new retry round tripper.

func (*TransportWrapperBuilder) Build

func (b *TransportWrapperBuilder) Build(ctx context.Context) (result *TransportWrapper, err error)

Build uses the information stored in the builder to create a new transport wrapper.

func (*TransportWrapperBuilder) Interval

Interval sets the time to wait before the first retry. The interval time will be doubled for each retry. For example, if this is set to one second then the first retry will happen approximately one second after the failure of the initial request, the second retry will happen affer four seconds, the third will happen after eitght seconds, so on.

func (*TransportWrapperBuilder) Jitter

Jitter sets a factor that will be used to randomize the retry intervals. For example, if this is set to 0.1 then a random adjustment between -10% and +10% will be done to the interval for each retry. This is intended to reduce simultaneous retries by clients when a server starts failing. The default value is 0.2.

func (*TransportWrapperBuilder) Limit

Limit sets the maximum number of retries for a request. When this is zero no retries will be performed. The default value is two.

func (*TransportWrapperBuilder) Logger

Logger sets the logger that will be used by the wrapper and by the round trippers that it creates.

Jump to

Keyboard shortcuts

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