Documentation ¶
Index ¶
- Constants
- func RateLimit(err error) error
- func Retryable(err error) error
- func Wrap(ctx context.Context, operation OperationFn, opts ...Option) error
- func WrapWithResult[T any](ctx context.Context, operation OperationWithResultFn[T], opts ...Option) (T, error)
- type Backoff
- type BackoffFactory
- type OperationFn
- type OperationWithResultFn
- type Option
- type RateLimitError
- type Retry
- type RetryWithResult
- type RetryableError
Constants ¶
const (
DefaultMaxAttempts = 4
)
Variables ¶
This section is empty.
Functions ¶
func RateLimit ¶
RateLimit returns an error that indicates that the operation should be retried after a delay.
Types ¶
type BackoffFactory ¶
type BackoffFactory func() Backoff
BackoffFactory returns a new instance of backoff policy.
type OperationFn ¶
type Option ¶
type Option func(r *retryOptions)
func WithBackoffFactory ¶
func WithBackoffFactory(backoffFactory BackoffFactory) Option
WithBackoffFactory sets the backoff factory. The default backoff factory creates an exponential backoff policy.
func WithLogger ¶
WithLogger sets the logger. The default logger is zap.NewNop().
func WithMaxAttempts ¶
func WithMaxAttempts(maxAttempts int) Option
WithMaxAttempts sets the maximum number of attempts. The default value is 3. Note that when maxAttempts is 1, the operation is executed only once without any retry.
type RateLimitError ¶
type RateLimitError struct {
Err error
}
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
type Retry ¶
Retry is a simple wrapper on top of "cenkalti/backoff" to provide retry functionalities. Main differences with "cenkalti/backoff": * By default, only RetryableError and RateLimitError are retried. In "cenkalti/backoff", all errors except for PermanentError are retried. * It is compatible with xerrors, i.e. you may wrap a RetryableError and the default Filter uses xerrors.As to determine if the error is a RetryableError. * Retry is aborted if either MaxElapsedTime or MaxAttempts is exceeded.
type RetryWithResult ¶
type RetryWithResult[T any] interface { Retry(ctx context.Context, operation OperationWithResultFn[T]) (T, error) }
RetryWithResult is similar to Retry except that the operation returns a generic result.
func NewWithResult ¶
func NewWithResult[T any](opts ...Option) RetryWithResult[T]
NewWithResult creates a new instance of RetryWithResult that works with `func(ctx context.Context) (T, error)`.
func ToRetryWithResult ¶
func ToRetryWithResult(r Retry) RetryWithResult[struct{}]
ToRetryWithResult converts Retry to RetryWithResult[struct{}].
type RetryableError ¶
type RetryableError struct {
Err error
}
func (*RetryableError) Error ¶
func (e *RetryableError) Error() string
func (*RetryableError) Unwrap ¶
func (e *RetryableError) Unwrap() error