retry

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPermanentError

func IsPermanentError(err error) bool

IsPermanentError returns true if an error value is or contains a PermanentError in its chain of errors.

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError returns true if an error value is or contains a TemporaryError in its chain of errors.

func Permanent

func Permanent(cause error) error

Permanent creates a PermanentError that signals to a retry loop that it should stop retrying an operation and return the underlying error.

func Temporary

func Temporary(message string) error

Temporary creates a TemporaryError that signals to a retry loop that an operation can be retried. The error may also carry details about how long to wait before retrying. This wait interval may be used to override the retry policy in use.

func TemporaryFromResponse

func TemporaryFromResponse(message string, res *http.Response) error

TemporaryFromResponse creates a TemporaryError similar to Temporary but additionally parses the Retry-After header from a response to determine the wait interval before the next retry attempt.

Types

type BackoffStrategy

type BackoffStrategy struct {
	InitialInterval int
	MaxInterval     int
	Exponent        float64
	MaxElapsedTime  int
}

BackoffStrategy defines the parameters for exponential backoff. This can be used to drive a retry loop for example.

type Config

type Config struct {
	// Strategy sets the algorithm to use for a retry loop. It can be one of:
	//   - "backoff": retry with exponential backoff and random jitter.
	//   - "none" or "": disables retries.
	Strategy              string
	Backoff               *BackoffStrategy
	RetryConnectionErrors bool
}

Config configures a retry policy.

type PermanentError

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

PermanentError is an error that signals that some operation has terminally failed and should not be retried.

func (*PermanentError) Error

func (e *PermanentError) Error() string

func (*PermanentError) Unwrap

func (e *PermanentError) Unwrap() error

type TemporaryError

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

TemporaryError represents a retryable error and signals to a retry loop that an operation may be retried with an optional wait interval.

func (*TemporaryError) Error

func (e *TemporaryError) Error() string

func (*TemporaryError) RetryAfter

func (e *TemporaryError) RetryAfter() time.Duration

RetryAfter returns the time to wait before retrying the request. The zero value should be interpreted by retry loops to mean they should fallback on their default policy whether expenonential, constant backoff or something else. It does not mean that an operation should be retried immediately.

Jump to

Keyboard shortcuts

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