go-sarah: github.com/oklahomer/go-sarah/retry Index | Files

package retry

import "github.com/oklahomer/go-sarah/retry"

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


Package Files


func Retry Uses

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 Uses

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 Uses

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

WithInterval retries given function at interval.

func WithPolicy Uses

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.

type Errors Uses

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 Uses

func (e *Errors) Error() string

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

type Policy Uses

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 Uses

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().

Package retry imports 3 packages (graph) and is imported by 1 packages. Updated 2019-08-12. Refresh now. Tools for package owners.