retry

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinDelay                 = 1 * time.Second  // Initial delay for retry interval.
	MaxInterval              = 60 * time.Second // Maximum interval an individual retry may have.
	MaxElapsedTime           = 0 * time.Second  // Maximum time all retries may take. `0` corresponds to no limit on the time of the retries.
	RetryFactor      float64 = 2                // Multiplier factor computed exponential retry interval is scaled by.
	NumRetries       uint64  = 3                // Total number of retries attempted.
	MinDelayChain            = 12 * time.Second // Initial delay for retry interval for contract calls. Corresponds to 1 ethereum block.
	MaxIntervalChain         = 2 * time.Minute  // Maximum interval for an individual retry.
)

Variables

This section is empty.

Functions

func Retry

func Retry(functionToRetry func() error, minDelay time.Duration, factor float64, maxTries uint64, maxInterval time.Duration, maxElapsedTime time.Duration) error

Retries a given function in an exponential backoff manner. It will retry calling the function while it returns an error, until the max retries. If maxTries == 0 then the retry function will run indefinitely until success from the configuration are reached, or until a `PermanentError` is returned. The function to be retried should return `PermanentError` when the condition for stop retrying is met.

func RetryWithData

func RetryWithData[T any](functionToRetry func() (T, error), minDelay time.Duration, factor float64, maxTries uint64, maxInterval time.Duration, maxElapsedTime time.Duration) (T, error)

Same as Retry only that the functionToRetry can return a value upon correct execution

Types

type PermanentError

type PermanentError struct {
	Inner error
}

Note we use a custom Permanent error type for asserting Permanent Erros within the retry library. We do not implement an explicit Transient error type and operate under the assumption that all errors that are not Permanent are Transient.

func (PermanentError) Error

func (e PermanentError) Error() string

func (PermanentError) Is

func (e PermanentError) Is(err error) bool

func (PermanentError) Unwrap

func (e PermanentError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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