retry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBackoff duration 2 secs
	DefaultBackoff = 2

	// LinearBackoff duration starts from 1 second
	LinearBackoff = 1

	// ExponetialFactor 1.5 per retry attempts
	ExponetialFactor = 1.5
)
View Source
var (
	// ErrRetryMaxLimit : ErrMsg after max retry failure
	ErrRetryMaxLimit = errors.New("Retry Limit Exceed!")

	// DefaultRetryCount : the number of retry attempts
	DefaultRetryCount int = 5
)

Functions

func IsContextError

func IsContextError(err error) bool

IsContextError verifies the error codes with context based error codes.

func IsRetriable

func IsRetriable(err error, codes []codes.Code) bool

IsRetriable verifies the error codes with the defined retriable codes.

func RetryClientConnection

func RetryClientConnection(factory ClientConnFactory, retryOption *RetryOption) (*grpc.ClientConn, error)

RetryClientConnection function will retry gRPC connection for max retry count using the ClientConnFactory.

Types

type Backoff

type Backoff struct {
	Strategy BackoffStrategy
}

Backoff struct defines the backoff strategy type

func (*Backoff) ApplyBackoffDuration

func (b *Backoff) ApplyBackoffDuration(attempt int)

ApplyBackoffDuration will decide a backoff strategy for a retry attempt.

type BackoffStrategy

type BackoffStrategy int

BackoffStrategy type

const (
	Default BackoffStrategy = iota // BackoffStrategy constants
	Jitter
	Linear
	Exponetial
)

type ClientConnFactory

type ClientConnFactory func(address string) (*grpc.ClientConn, error)

ClientConnFactory is the abstract connection factory function to retry multiple times.

type ConnState

type ConnState connectivity.State

ConnState : Connectivity State of gRPC connection [Idle,Connecting,Ready,TransientFailure,Shutdown]

const (
	Idle ConnState = iota // ConnState constants
	Connecting
	Ready
	TransientFailure
	ShutDown
)

type RetryOption

type RetryOption struct {
	Retry   int
	Address string
	Backoff *Backoff
	Codes   []codes.Code
}

RetryOption struct defines the configuration for retry behavior for the gRPC connection failure,

Retry: The number of retry attempts for gRPC connection retry.

Address: The target address of the server used for retry.

Backoff: The backoff strategy applies delays for each retry attempt.

Codes: A list of codes retriable codes that get matched with the error codes.

func (*RetryOption) RetryBackoff

func (r *RetryOption) RetryBackoff(attempt int) error

RetryBackoff will apply the backoff strategy to provides a delay to each retry attempt.

Jump to

Keyboard shortcuts

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