retry

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Stable represents fixed time wait retry policy, every retry should wait a fixed time
	Stable backoffStrategy = iota + 1
	// LinearIncrease represents increase time wait retry policy, every retry should wait more time depends on increasing retry times
	LinearIncrease
)

Variables

This section is empty.

Functions

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError tells whether this error should retry

Types

type FiniteRetryStrategy

type FiniteRetryStrategy struct {
}

FiniteRetryStrategy will retry `RetryCount` times when failed to operate DB.

func (*FiniteRetryStrategy) Apply

func (*FiniteRetryStrategy) Apply(ctx *tcontext.Context, params Params,
	operateFn func(*tcontext.Context) (interface{}, error)) (ret interface{}, i int, err error)

Apply for FiniteRetryStrategy, it wait `FirstRetryDuration` before it starts first retry, and then rest of retries wait time depends on BackoffStrategy.

type Params

type Params struct {
	RetryCount         int
	FirstRetryDuration time.Duration

	BackoffStrategy backoffStrategy

	// IsRetryableFn tells whether we should retry when operateFn failed
	// params: (number of retry, error of operation)
	// return: (bool)
	//   1. true: means operateFn can be retried
	//   2. false: means operateFn cannot retry after receive this error
	IsRetryableFn func(int, error) bool
}

Params define parameters for Apply it's a parameters union set of all implements which implement Apply

type Strategy

type Strategy interface {

	// Apply define retry strategy
	// params: (retry parameters for this strategy, a normal operation)
	// return: (result of operation, number of retry, error of operation)
	Apply(ctx *tcontext.Context,
		params Params,

		operateFn func(*tcontext.Context) (interface{}, error),
	) (interface{}, int, error)
}

Strategy define different kind of retry strategy

Jump to

Keyboard shortcuts

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