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 ¶
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
Click to show internal directories.
Click to hide internal directories.