Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Permanent is a wrapper function when you don't want retry // with some inner error. // 对于某些不想重试的错误, 可以用次方法包裹该错误, retry 便不再重试. Permanent = backoff.Permanent )
Functions ¶
func NotifyRecover ¶
func NotifyRecover(operation backoff.Operation, b backoff.BackOff, notify NotifyWithTimes, recovered func(times int), verbose bool) error
NotifyRecover is a wrapper around backoff.RetryNotify that adds another callback for when an operation previously failed but has since recovered. The main purpose of this wrapper is to call `notify` only when the operations fails the first time and `recovered` when it finally succeeds. This can be helpful in limiting log messages to only the events that operators need to be alerted on.
Types ¶
type Config ¶
type Config struct { Policy PolicyType // Constant back off Duration time.Duration // Exponential back off InitialInterval time.Duration RandomizationFactor float32 Multiplier float32 MaxInterval time.Duration MaxElapsedTime time.Duration // Additional options MaxRetries int64 }
Config encapsulates the back off policy configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig represents the default configuration for a `Config`.
func DefaultConfigWithNoRetry ¶
func DefaultConfigWithNoRetry() Config
DefaultConfigWithNoRetry represents the default configuration with `MaxRetries` set to 0. This may be useful for those brokers which can handles retries on its own.
func (*Config) NewBackOff ¶
func (c *Config) NewBackOff() backoff.BackOff
func (*Config) NewBackOffWithContext ¶
NewBackOffWithContext 为 backoff 增加 ctx 控制, 可以 timeout 和 cancel
type PolicyType ¶
type PolicyType int
PolicyType denotes if the back off delay should be constant or exponential.
const ( // PolicyConstant is a backoff policy that always returns the same backoff delay. PolicyConstant PolicyType = iota + 1 // PolicyExponential is a backoff implementation that increases the backoff period // for each retry attempt using a randomization function that grows exponentially. PolicyExponential )