retrier

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServer = errors.New("internal server error, response code > 500")
	ErrNotFound       = errors.New("resource not found, response code = 404")
	ErrResponseIsNil  = errors.New("'response' from downstream is nil")
	ErrExec           = errors.New("executor failed")

	ErrRequestIsNotHTTP  = errors.New("retrier request is not net_http.Request")
	ErrResponseIsNotHTTP = errors.New("retrier response is not net_http.Response")
)

Functions

This section is empty.

Types

type Backoff

type Backoff func(counter int) time.Duration

Backoff defines the strategy in which the duration is computed for the next retry

type BackoffConf

type BackoffConf struct {
	Name string
	Incr int
}

type Classifier

type Classifier func(error, interface{}) State

Classifier takes a given error generated by the Proxy and assigns a given state based on the error emitted

type Deadliner

type Deadliner interface {
	Deadline() (time.Duration, error)
}

type Executor

type Executor func(context.Context, *net_http.Request) (*net_http.Response, error)

type Jitter

type Jitter func() time.Duration

Jitter defines the randomization strategy which is added to backoff timer to not clog the the downstream with simulteneous requests

type Retrier

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

Retrier retries to perform a single operation multiple times based on the parameters provided

func NewExecutorRetrier

func NewExecutorRetrier(
	ex Executor,
	logger log.Logger,
	options ...RetrierOption,
) (*Retrier, error)

func NewRetrier

func NewRetrier(logger log.Logger, fn endpoint.Endpoint, options ...RetrierOption) (*Retrier, error)

NewRetrier returns a new Retrier

func NewRetrierFromConfig

func NewRetrierFromConfig(fn endpoint.Endpoint, lg log.Logger, cfg *RetrierConf, opts ...RetrierOption) (*Retrier, error)

NewRetrierFromConfig returns a new retrier based on configuration

func (*Retrier) Endpoint

func (r *Retrier) Endpoint() endpoint.Endpoint

Endpoint returns endpoint.Endpoint with retry wrapped

func (*Retrier) Executor

func (r *Retrier) Executor() Executor

type RetrierConf

type RetrierConf struct {
	// jitter & classifier can be taken from config
	// in similar fashion
	Backoff *BackoffConf
	// retry counts
	Count int
	// need to set in config,
	// default value is false for bool
	Enable bool
}

type RetrierOption

type RetrierOption func(*Retrier) error

RetrierOption sets options for Retry

func WithClassifier

func WithClassifier(cl Classifier) RetrierOption

func WithConstantBackoff

func WithConstantBackoff(conf *BackoffConf) RetrierOption

WithConstantBackoff increments the timer with a constant value

func WithLinearBackoff

func WithLinearBackoff(conf *BackoffConf) RetrierOption

WithLinearBackoff sets backoff as linear

func WithLogger

func WithLogger(logger log.Logger) RetrierOption

WithLogger sets the logger for retrier

func WithRetrierEnable

func WithRetrierEnable(en bool) RetrierOption

WithRetrierEnable sets if Retrier is enabled

func WithRetryCount

func WithRetryCount(count int) RetrierOption

WithRetryCount sets custom retry count for Retrier

type State

type State int

State defines the state of the connection

const (
	PASS State = iota
	FAIL
	RETRY
)

States

Jump to

Keyboard shortcuts

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