retry

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package retry provides general retry logic and designated error structure that contains multiple errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(trial uint, function func() error) error

Retry retries given function as many times as the maximum trial count. It quits retrial when the function returns no error, which is nil.

func WithBackOff

func WithBackOff(trial uint, function func() error, meanInterval time.Duration, randFactor float64) error

WithBackOff retries given function at interval, but the interval differs every time. The base interval and randomization factor are specified as 3rd and 4th arguments.

func WithInterval

func WithInterval(trial uint, function func() error, interval time.Duration) error

WithInterval retries given function at interval.

func WithPolicy added in v1.4.0

func WithPolicy(policy *Policy, function func() error) error

WithPolicy receives retrial policy and an executable function. Passed function is recursively executed as long as it returns an error or the retrial count exceeds given configuration value. Unlike other retrial functions, this function is among the most flexible since a user has maximum freedom on configuration.

Types

type Errors

type Errors []error

Errors is an alias for slice of error that contains ordered error that occurred during retrials. This implements Error method to satisfy error interface, which returns concatenated message of all belonging errors.

Since this is an alias to []error, each belonging error is accessible in a way such as:

for i, err := range *errs { ... }

func (*Errors) Error

func (e *Errors) Error() string

Error returns the concatenated message of all belonging errors. All err.Err() strings are joined with "\n".

type Policy added in v1.4.0

type Policy struct {
	Trial      uint          `json:"trial" yaml:"trial"`
	Interval   time.Duration `json:"interval" yaml:"interval"`
	RandFactor float64       `json:"random_factor" yaml:"random_factor"`
}

Policy represents a configuration value for retrial logic.

func NewPolicy added in v1.4.0

func NewPolicy() *Policy

NewPolicy creates and returns new retrial policy. To let developers supply flexible retrial policy from outside rather than obligating them to call a specific retry function, pass this returned value to retry.WithPolicy().

Jump to

Keyboard shortcuts

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