Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContextCanceled is returned if the context is cancelled or the deadline is reached ErrContextCanceled = fmt.Errorf("context cancelled") // ErrRequestNotRetriable is returned if the request fails and the error is not retriable (a 400, for example) ErrRequestNotRetriable = fmt.Errorf("request is not retriable") // ErrNotSuccessful is returned if the number of retries is exhausted without any successes ErrNotSuccessful = fmt.Errorf("request not successful") )
Functions ¶
func IsCanceledContextError ¶ added in v0.0.2
IsCanceledContextError returns true if the error is some variant of "context canceled" or "context deadline exceeded"
func IsContextDone ¶ added in v0.0.2
IsContextDone returns true if the context is done
Types ¶
type ActionFunc ¶
ActionFunc is the function which is called and retried in case of a failure
type BackoffFunc ¶
BackoffFunc is the backoff strategy. Given the number of attempts already made, it returns the wait time
type ErrorHandler ¶ added in v1.0.1
ErrorHandler is a function which is called before returning an error
type OnErrorFunc ¶
type OnErrorFunc func(err error)
OnErrorFunc is a callback function which is called every time the action returns an error
type Retrier ¶
type Retrier struct {
// contains filtered or unexported fields
}
Retrier performs a specified action with retry logic based on its configuration
func NewRetrier ¶
func NewRetrier(options ...RetrierOption) *Retrier
NewRetrier returns a new Retrier with the specified options
type RetrierOption ¶
type RetrierOption func(t *Retrier)
RetrierOption is a callback for specifying configuration options for a Retrier
func WithBackoff ¶
func WithBackoff(backoff BackoffFunc) RetrierOption
WithBackoff allows you to specify the backoff strategy, for example an exponential backoff
func WithIgnoreCtx ¶ added in v1.0.0
func WithIgnoreCtx(ignoreCtx bool) RetrierOption
WithIgnoreCtx is an option to specify whether context canncelation/deadline should be ignored (will retry anyway if true)
func WithMaxAttempts ¶
func WithMaxAttempts(maxAttempts uint) RetrierOption
WithMaxAttempts is an option to specify the maximum number of retries which the Retrier should make
func WithOnError ¶
func WithOnError(onError OnErrorFunc) RetrierOption
WithOnError is an option to specify the OnError callback which is called for each failed attempt
func WithPassThroughErrorHandler ¶ added in v1.0.1
func WithPassThroughErrorHandler() RetrierOption
WithPassThroughErrorHandler is an option to specify that the Retrier should return original error returned by the action