Documentation ¶
Index ¶
- func DecodeConfig(c *Config, input interface{}) error
- func DecodeConfigWithPrefix(c *Config, input interface{}, prefix string) error
- func Normalize(i interface{}) (interface{}, error)
- func NotifyRecover(operation backoff.Operation, b backoff.BackOff, notify backoff.Notify, ...) error
- func NotifyRecoverWithData[T any](operation backoff.OperationWithData[T], b backoff.BackOff, ...) (T, error)
- func PrefixedBy(input interface{}, prefix string) (interface{}, error)
- type Config
- type PolicyType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeConfig ¶
DecodeConfig decodes a Go struct into a `Config`.
func DecodeConfigWithPrefix ¶
DecodeConfigWithPrefix decodes a Go struct into a `Config`.
func NotifyRecover ¶
func NotifyRecover(operation backoff.Operation, b backoff.BackOff, notify backoff.Notify, recovered func()) 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.
func NotifyRecoverWithData ¶
func NotifyRecoverWithData[T any](operation backoff.OperationWithData[T], b backoff.BackOff, notify backoff.Notify, recovered func()) (T, error)
NotifyRecoverWithData is a variant of NotifyRecover that also returns data in addition to an error.
func PrefixedBy ¶
Types ¶
type Config ¶
type Config struct { Policy PolicyType `mapstructure:"policy"` // Constant back off Duration time.Duration `mapstructure:"duration"` // Exponential back off InitialInterval time.Duration `mapstructure:"initialInterval"` RandomizationFactor float32 `mapstructure:"randomizationFactor"` Multiplier float32 `mapstructure:"multiplier"` MaxInterval time.Duration `mapstructure:"maxInterval"` MaxElapsedTime time.Duration `mapstructure:"maxElapsedTime"` // Additional options MaxRetries int64 `mapstructure:"maxRetries"` }
Config encapsulates the back off policy configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig represents the default configuration for a `Config`.
func (*Config) NewBackOff ¶
func (c *Config) NewBackOff() backoff.BackOff
NewBackOff returns a BackOff instance for use with `NotifyRecover` or `backoff.RetryNotify` directly. The instance will not stop due to context cancellation. To support cancellation (recommended), use `NewBackOffWithContext`.
Since the underlying backoff implementations are not always thread safe, `NewBackOff` or `NewBackOffWithContext` should be called each time `RetryNotifyRecover` or `backoff.RetryNotify` is used.
func (*Config) NewBackOffWithContext ¶
NewBackOffWithContext returns a BackOff instance for use with `RetryNotifyRecover` or `backoff.RetryNotify` directly. The provided context is used to cancel retries if it is canceled.
Since the underlying backoff implementations are not always thread safe, `NewBackOff` or `NewBackOffWithContext` should be called each time `RetryNotifyRecover` or `backoff.RetryNotify` is used.
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 // PolicyExponential is a backoff implementation that increases the backoff period // for each retry attempt using a randomization function that grows exponentially. PolicyExponential )
func (*PolicyType) DecodeString ¶
func (p *PolicyType) DecodeString(value string) error
DecodeString handles converting a string value to `p`.
func (PolicyType) String ¶
func (p PolicyType) String() string
String implements fmt.Stringer and is used for debugging.