retry

package
v0.0.0-...-150c8f6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBackoff

func DefaultBackoff(_ uint, c *Config) time.Duration

DefaultBackoff always returns a fixed delay duration.

func Do

func Do(ctx context.Context, logger *zap.Logger, scope tally.Scope, fn RetryableFunc, opts ...Option) error

Do retries a given function with delays between each attempts as defined by the caller or their corresponding defaults.

err := retry.Do(
	ctx,
	logger,
	scope,
	func() error { return nil },
	Backoff(ExponentialBackoff),
)

func ExponentialBackoff

func ExponentialBackoff(i uint, _ *Config) time.Duration

ExponentialBackoff returns exponentially increasing backoffs by a power of 2.

func JitterBackoff

func JitterBackoff(_ uint, c *Config) time.Duration

JitterBackoff returns a random delay duration up to maxJitter.

Types

type BackoffStrategy

type BackoffStrategy func(uint, *Config) time.Duration

BackoffStrategy is used to determine the delay between retries.

type Config

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

Config defines the behavior of retries.

type MultiError

type MultiError []error

MultiError is a slice of errors ocurred while retrying.

func (MultiError) Error

func (m MultiError) Error() string

Error implements the error interface.

Returns all the errors occurred during retry formatted as a string separated by newlines.

type Option

type Option func(*Config)

Option is an option for retry.

func Backoff

func Backoff(backoff BackoffStrategy) Option

Backoff sets the backoff mechanism used while retrying.

func Delay

func Delay(delay time.Duration) Option

Delay sets the delay between each retries.

func Jitter

func Jitter(jitter time.Duration) Option

Jitter sets the max jitter. Defaults to 100ms if provided value <= 0.

func Retries

func Retries(count uint) Option

Retries sets the total number of attempts.

type RetryableFunc

type RetryableFunc func() error

RetryableFunc represents a function that is retryable.

Jump to

Keyboard shortcuts

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