retry

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxWaitTime = 15 * time.Minute // 15 minutes
)

Variables

This section is empty.

Functions

func WaitTime added in v0.1.1

func WaitTime(attempt int, random *rand.Rand, maxWaitTime time.Duration) time.Duration

WaitTime calculates the wait time based off the attempt number based off exponential backoff with a random delay. It caps at the passed in maxWaitTime.

Types

type NonRetryableError added in v0.6.0

type NonRetryableError struct {
	Err error
}

NonRetryableError represents an error returned if the error should not be retried

func (*NonRetryableError) Error added in v0.6.0

func (e *NonRetryableError) Error() string

Error returns an error string

func (*NonRetryableError) Unwrap added in v0.6.0

func (e *NonRetryableError) Unwrap() error

Unwrap returns the underlying error

type Retry

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

Retry handles executing and retrying a function It uses exponential backoff between retry attempts

func NewRetry

func NewRetry(maxRetry int, seed int64) Retry

NewRetry initializes a retry handler maxRetry is *retries*, so maxRetry of 2 means 3 total tries. -1 retries means indefinite retries

func NewRetryWithMaxWaitTime added in v0.7.0

func NewRetryWithMaxWaitTime(maxRetry int, seed int64, maxWaitTime time.Duration) Retry

NewRetryWithMaxWaitTime initializes a retry handler maxRetry is *retries*, so maxRetry of 2 means 3 total tries. -1 retries means indefinite retries

func NewTestRetry

func NewTestRetry(maxRetry int) Retry

NewTestRetry is the test version, returns Retry in test mode (nanosecond retry delay).

func (Retry) Do

func (r Retry) Do(ctx context.Context, f func(context.Context) error, desc string) error

Do calls a function with exponential retries with a random delay.

Jump to

Keyboard shortcuts

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