retry

package
v0.0.0-...-485a10e Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, operation Operation, opts ...Option) error

Do execute the specified function at most maxTries times until it succeeds or got canceled

func Run

func Run(initialInterval time.Duration, maxRetries uint64, f func() error) error

Run is Deprecated, try to use Do instead. Run retries the specified function on error for at most maxRetries times. It stops retry if the returned error is context.Canceled or context.DeadlineExceeded.

func RunWithInfiniteRetry

func RunWithInfiniteRetry(initialInterval time.Duration, f func() error, notifyFunc func(elapsed time.Duration)) error

RunWithInfiniteRetry is Deprecated, try to use instead Do WithInfiniteTries option instead. RunWithInfiniteRetry retries the specified function indefinitely, until a backoff.PermanentError is encountered. notifyFunc will be called each time before sleeping with the total elapsed time.

Types

type IsRetryable

type IsRetryable func(error) bool

IsRetryable checks the error is safe or worth to retry, eg. "context.Canceled" better not retry

type Operation

type Operation func() error

Operation is the action need to retry

type Option

type Option func(*retryOptions)

Option ...

func WithBackoffBaseDelay

func WithBackoffBaseDelay(delayInMs int64) Option

WithBackoffBaseDelay configures the initial delay, if delayInMs <= 0 "defaultBackoffBaseInMs" will be used

func WithBackoffMaxDelay

func WithBackoffMaxDelay(delayInMs int64) Option

WithBackoffMaxDelay configures the maximum delay, if delayInMs <= 0 "defaultBackoffCapInMs" will be used

func WithInfiniteTries

func WithInfiniteTries() Option

WithInfiniteTries configures to retry forever (math.MaxInt64 times) till success or got canceled

func WithIsRetryableErr

func WithIsRetryableErr(f IsRetryable) Option

WithIsRetryableErr configures the error should retry or not, if not set, retry by default

func WithMaxTries

func WithMaxTries(tries int64) Option

WithMaxTries configures maximum tries, if tries <= 0 "defaultMaxTries" will be used

Jump to

Keyboard shortcuts

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