retrier

package
v0.18.6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(maxRetries int, backOffPeriod time.Duration, fn func() error) error

Retry runs fn with a MaxRetriesPolicy.

Types

type Retrier

type Retrier struct {
	// contains filtered or unexported fields
}

func New

func New(timeout time.Duration, opts ...RetrierOpt) *Retrier

New creates a new retrier with a global timeout (max time allowed for the whole execution) The default retry policy is to always retry with no wait time in between retries.

func NewWithMaxRetries

func NewWithMaxRetries(maxRetries int, backOffPeriod time.Duration) *Retrier

NewWithMaxRetries creates a new retrier with no global timeout and a max retries policy.

func NewWithNoTimeout added in v0.14.4

func NewWithNoTimeout() *Retrier

NewWithNoTimeout creates a new retrier with no global timeout and infinite retries.

func (*Retrier) Retry

func (r *Retrier) Retry(fn func() error) error

Retry runs the fn function until it either successful completes (not error), the set timeout reached or the retry policy aborts the execution.

type RetrierOpt

type RetrierOpt func(*Retrier)

func WithBackoffFactor added in v0.7.0

func WithBackoffFactor(factor float32) RetrierOpt

func WithMaxRetries

func WithMaxRetries(maxRetries int, backOffPeriod time.Duration) RetrierOpt

WithMaxRetries sets a retry policy that will retry up to maxRetries times with a wait time between retries of backOffPeriod.

func WithRetryPolicy

func WithRetryPolicy(policy RetryPolicy) RetrierOpt

type RetryPolicy

type RetryPolicy func(totalRetries int, err error) (retry bool, wait time.Duration)

RetryPolicy allows to customize the retrying logic. The boolean retry indicates if a new retry should be performed and the wait duration indicates the wait time before the next retry.

func BackOffPolicy added in v0.18.0

func BackOffPolicy(backoff time.Duration) RetryPolicy

BackOffPolicy retries until top level timeout is reached, waiting a backoff period in between retries.

Jump to

Keyboard shortcuts

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