thirdparty

package
v0.9.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: AGPL-3.0 Imports: 9 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 Normalize

func Normalize(i interface{}) (interface{}, error)

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

func PrefixedBy(input interface{}, prefix string) (interface{}, error)

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.

func (Config) String

func (c Config) String() string

String implements fmt.Stringer and is used for debugging.

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.

Jump to

Keyboard shortcuts

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