Skip to content

darylnwk/retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

retry

-- import "github.com/darylnwk/retry"

Usage

func ConstantBackoff

func ConstantBackoff(_ uint, delay time.Duration) time.Duration

ConstantBackoff defines constant backoff strategy

func ExponentialBackoff

func ExponentialBackoff(n uint, delay time.Duration) time.Duration

ExponentialBackoff defines exponential backoff strategy

func Jitter

func Jitter(backoff time.Duration) time.Duration

Jitter defines a full jitter strategy

func NoBackoff

func NoBackoff(_ uint, _ time.Duration) time.Duration

NoBackoff defines no backoff strategy

func NoJitter

func NoJitter(backoff time.Duration) time.Duration

NoJitter defines no jitter strategy

type Errors

type Errors []error

Errors defines a list of error

func (Errors) Error

func (errs Errors) Error() string

type Retryer

type Retryer struct {
	// Attempts defines the number of retry attempts.
	// Default 1.
	Attempts uint

	// Backoff defines a backoff function that returns `time.Duration`.
	// This is applied on subsequent attempts.
	// Default no backoff.
	Backoff func(n uint, delay time.Duration) time.Duration

	// Jitter defines a jitter function that returns `time.Duration`.
	// Default no jitter.
	Jitter func(backoff time.Duration) time.Duration

	// Delay defines duration to delay.
	// Default 0.
	Delay time.Duration
}

Retryer defines a retryer

func (Retryer) Do

func (retryer Retryer) Do(fn func() error) (bool, Errors)

Do executes fn and returns success if fn executed succesfully and any errors that occurred