Documentation ¶
Index ¶
- Variables
- func IsRetriable(err error) bool
- func MinorError(minorErr error) (bool, error)
- func MinorOrSevereError(retryCountUntilSevere, threshold int, err error) (bool, error)
- func NewError(ctxError, err error) error
- func NotOk() (bool, error)
- func Ok() (bool, error)
- func RetriableError(err error) error
- func SevereError(severeErr error) (bool, error)
- func UntilFor(ctx context.Context, waitFunc WaitFunc, agg ErrorAggregator, f Func) error
- type Error
- type ErrorAggregator
- type ErrorAggregatorFactory
- type ErrorAggregatorFactoryFunc
- type Func
- type IntervalFactory
- type IntervalFactoryFunc
- type Ops
- type WaitFunc
Constants ¶
This section is empty.
Variables ¶
var ( // Until is an alias for `DefaultOps().Until`. Until = DefaultOps().Until // UntilTimeout is an alias for `DefaultOps().New`. UntilTimeout = DefaultOps().UntilTimeout // Interval is an alias for `DefaultIntervalFactory().New`. Interval = DefaultIntervalFactory().New )
Functions ¶
func IsRetriable ¶ added in v1.25.0
IsRetriable checks if any error in err's chain is marked as an retriableError.
func MinorError ¶
MinorError indicates an operation was not successful due to the given error but can be retried.
func MinorOrSevereError ¶ added in v1.5.1
MinorOrSevereError returns a "severe" error in case the retry count exceeds the threshold. Otherwise, it returns a "minor" error.
func NewError ¶ added in v1.16.0
NewError returns a new error with the given context error and error. The non-context error is optional.
func NotOk ¶
NotOk indicates that an operation was not successful but can be retried. It does not indicate an error. For better error reporting, consider MinorError.
func RetriableError ¶ added in v1.25.0
RetriableError marks a given error as retriable.
func SevereError ¶
SevereError indicates an operation was not successful due to the given error and cannot be retried.
Types ¶
type Error ¶ added in v1.16.0
type Error struct {
// contains filtered or unexported fields
}
Error is an error that occurred during a retry operation.
func (*Error) Unwrap ¶ added in v1.16.0
Unwrap implements the Unwrap function https://golang.org/pkg/errors/#Unwrap
type ErrorAggregator ¶
type ErrorAggregator interface { // Minor records the given minor error. Minor(err error) // Severe records the given severe error. Severe(err error) // Error returns the aggregated error. Error() error }
An ErrorAggregator aggregates minor and severe errors.
It's completely up to the ErrorAggregator how to aggregate the errors. Some may choose to only keep the most recent error they received. If no error was being recorded and the Error function is being called, the ErrorAggregator should return a proper zero value (in most cases, this will be nil).
func NewLastErrorAggregator ¶
func NewLastErrorAggregator() ErrorAggregator
NewLastErrorAggregator returns an ErrorAggregator that only keeps the last error it recorded.
type ErrorAggregatorFactory ¶
type ErrorAggregatorFactory interface {
New() ErrorAggregator
}
ErrorAggregatorFactory is a factory that produces ErrorAggregators.
func DefaultErrorAggregatorFactory ¶
func DefaultErrorAggregatorFactory() ErrorAggregatorFactory
DefaultErrorAggregatorFactory returns the default ErrorAggregatorFactory.
type ErrorAggregatorFactoryFunc ¶
type ErrorAggregatorFactoryFunc func() ErrorAggregator
ErrorAggregatorFactoryFunc is a function that implements ErrorAggregatorFactory.
func (ErrorAggregatorFactoryFunc) New ¶
func (f ErrorAggregatorFactoryFunc) New() ErrorAggregator
New implements ErrorAggregatorFactory.
type Func ¶
Func is a function that can be retried.
There four possible return combinations. For each of these, there's also a utility function: * Ok (true, nil): Execution succeeded without error. * NotOk (false, nil): Execution failed without error, can be retried. * MinorError (false, err): Execution failed with error, can be retried. * SevereError (true, err): Execution failed with error, cannot be retried.
type IntervalFactory ¶
IntervalFactory is a factory that can produce WaitFuncs that wait for the given interval.
func DefaultIntervalFactory ¶
func DefaultIntervalFactory() IntervalFactory
DefaultIntervalFactory returns the default IntervalFactory.
func NewIntervalFactory ¶
func NewIntervalFactory(contextOps utilcontext.Ops) IntervalFactory
NewIntervalFactory returns a new IntervalFactory using the given utilcontext.Ops.
type IntervalFactoryFunc ¶
IntervalFactoryFunc is a function that implements IntervalFactory.
type Ops ¶
type Ops interface { // Until keeps retrying the given Func until it either errors severely or the context expires. // Between each try, it waits for the given interval. Until(ctx context.Context, interval time.Duration, f Func) error // UntilTimeout keeps retrying the given Func until it either errors severely or the context expires. // Between each try, it waits for the given interval. // It also passes down a modified context to the execution that times out after the given timeout. UntilTimeout(ctx context.Context, interval, timeout time.Duration, f Func) error }
Ops are additional operations that can be done based on the UntilFor method.
func DefaultOps ¶
func DefaultOps() Ops
DefaultOps returns the default Ops with the DefaultIntervalFactory, DefaultErrorAggregatorFactory and utilcontext.DefaultOps.
func NewOps ¶
func NewOps(intervalFactory IntervalFactory, errorAggregatorFactory ErrorAggregatorFactory, contextOps utilcontext.Ops) Ops
NewOps returns the new ops with the given IntervalFactory, ErrorAggregatorFactory and utilcontext.Ops.