wait

package
v0.0.0-...-21311fb Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewUnlimitedExponentialBackoff

func NewUnlimitedExponentialBackoff() libbackoff.BackOff

NewUnlimitedExponentialBackoff returns a new exponential backoff interval without time limit

func Retry

func Retry(ctx context.Context, fn func() error) error

Retry attempts to execute fn with default delay retrying it for a default number of attempts. fn can return AbortRetry to abort or ContinueRetry to continue the execution.

func RetryWithInterval

func RetryWithInterval(ctx context.Context, interval libbackoff.BackOff, fn func() error, logger log.FieldLogger) error

RetryWithInterval retries the specified operation fn using the specified backoff interval

func Sleep

func Sleep(ctx context.Context, d time.Duration)

Sleep is context-interruptable sleep

Types

type AbortRetry

type AbortRetry struct {
	Err error
}

AbortRetry if returned from Retry, will lead to retries to be stopped, but the Retry function will return internal Error

func Abort

func Abort(err error) AbortRetry

Abort causes Retry function to stop with error

func (AbortRetry) Error

func (r AbortRetry) Error() string

type ContinueRetry

type ContinueRetry struct {
	Message string
}

ContinueRetry if returned from Retry, will be lead to retry next time

func Continue

func Continue(format string, args ...interface{}) ContinueRetry

Continue causes Retry function to continue trying and logging message

func (ContinueRetry) Error

func (r ContinueRetry) Error() string

type Retryer

type Retryer struct {
	// Delay specifies the interval between retry attempts
	Delay time.Duration
	// Attempts specifies the number of attempts to execute before failing.
	// Should be >= 1, zero value is not useful
	Attempts int
	// FieldLogger specifies the log sink
	log.FieldLogger
}

Retryer is a process that can retry a function

func (Retryer) Do

func (r Retryer) Do(ctx context.Context, fn func() error) (err error)

Do retries the given function fn for the configured number of attempts until it succeeds or all attempts have been exhausted

Jump to

Keyboard shortcuts

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