retry

package
v1.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeConfig

func DecodeConfig(c *Config, input interface{}) error

DecodeConfig decodes a Go struct into a `Config`.

func DecodeConfigWithPrefix

func DecodeConfigWithPrefix(c *Config, input interface{}, prefix string) error

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.

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

func (c *Config) NewBackOffWithContext(ctx context.Context) backoff.BackOff

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`.

Jump to

Keyboard shortcuts

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