Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶ added in v1.0.5
type Option func(*Retrier)
Option is a function type that can be used to configure the `Retrier` struct.
func WithInterval ¶ added in v1.0.5
WithInterval returns an option that sets the interval.
func WithJitter ¶ added in v1.0.5
WithJitter returns an option that sets the jitter.
func WithMaxRetries ¶ added in v1.0.5
WithMaxRetries returns an option that sets the maximum number of retries.
func WithTimeout ¶ added in v1.0.5
WithTimeout returns an option that sets the timeout.
type Retrier ¶
type Retrier struct {
// MaxRetries is the maximum number of retries.
MaxRetries int
// Jitter is the amount of jitter to apply to the retry interval.
Jitter time.Duration
// Interval is the interval between retries.
Interval time.Duration
// Timeout is the timeout for the retry function.
Timeout time.Duration
// Registry is the registry for temporary errors.
Registry *registry
// contains filtered or unexported fields
}
Retrier is a type that retries a function until it returns a nil error or the maximum number of retries is reached.
func NewRetrier ¶
NewRetrier returns a new Retrier configured with the given options. If no options are provided, the default options are used. The default options are:
- MaxRetries: 5
- Jitter: 1 * time.Second
- Interval: 500 * time.Millisecond
- Timeout: 20 * time.Second
func (*Retrier) Cancel ¶ added in v1.0.4
func (r *Retrier) Cancel()
Cancel cancels the retries notifying the `Retry` function to return.
func (*Retrier) IsTemporaryError ¶
IsTemporaryError checks if the error is in the list of temporary errors.
func (*Retrier) Retry ¶
func (r *Retrier) Retry(ctx context.Context, retryableFunc RetryableFunc, temporaryErrors ...string) error
Retry retries a `retryableFunc` until it returns a nil error or the maximum number of retries is reached.
- If the maximum number of retries is reached, the function returns a `RetryError` object.
- If the `retryableFunc` returns a nil error, the function returns nil.
- If the `retryableFunc` returns a temporary error, the function retries the function.
- If the `retryableFunc` returns a non-temporary error, the function returns the error.
- If the `temporaryErrors` list is empty, the function retries the function until the maximum number of retries is reached.
- The context is used to cancel the retries, or set a deadline if the `retryableFunc` hangs.
func (*Retrier) SetRegistry ¶
func (r *Retrier) SetRegistry(reg *registry)
SetRegistry sets the registry for temporary errors.
type RetryError ¶
RetryError is an error returned by the Retry function when the maximum number of retries is reached.
func (*RetryError) Unwrap ¶
func (e *RetryError) Unwrap() error
Unwrap returns the underlying error.
type RetryableFunc ¶ added in v1.0.5
type RetryableFunc func() error
Function signature of retryable function
type TemporaryError ¶ added in v1.0.5
type TemporaryError error
TemporaryError implements the error interface.