gardener: github.com/gardener/gardener/pkg/utils/retry Index | Files

package retry

import "github.com/gardener/gardener/pkg/utils/retry"

Index

Package Files

alias.go retry.go types.go

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
)

func MinorError Uses

func MinorError(minorErr error) (done bool, err error)

MinorError indicates an operation was not successful due to the given error but can be retried.

func NewRetryError Uses

func NewRetryError(ctxError, err error) error

NewRetryError returns a new error with the given context error and error. The non-context error is optional.

func NotOk Uses

func NotOk() (done bool, err error)

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 Ok Uses

func Ok() (done bool, err error)

Ok indicates that an operation was successful and does not need to be retried.

func SevereError Uses

func SevereError(severeErr error) (done bool, err error)

SevereError indicates an operation was not successful due to the given error and cannot be retried.

func UntilFor Uses

func UntilFor(ctx context.Context, waitFunc WaitFunc, agg ErrorAggregator, f Func) error

UntilFor keeps retrying the given Func until it either errors severely or the context expires. Between each try, it waits using the context of the given WaitFunc.

type ErrorAggregator Uses

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 Uses

func NewLastErrorAggregator() ErrorAggregator

NewLastErrorAggregator returns an ErrorAggregator that only keeps the last error it recorded.

type ErrorAggregatorFactory Uses

type ErrorAggregatorFactory interface {
    New() ErrorAggregator
}

ErrorAggregatorFactory is a factory that produces ErrorAggregators.

func DefaultErrorAggregatorFactory Uses

func DefaultErrorAggregatorFactory() ErrorAggregatorFactory

DefaultErrorAggregatorFactory returns the default ErrorAggregatorFactory.

type ErrorAggregatorFactoryFunc Uses

type ErrorAggregatorFactoryFunc func() ErrorAggregator

ErrorAggregatorFactoryFunc is a function that implements ErrorAggregatorFactory.

func (ErrorAggregatorFactoryFunc) New Uses

func (f ErrorAggregatorFactoryFunc) New() ErrorAggregator

New implements ErrorAggregatorFactory.

type Func Uses

type Func func(ctx context.Context) (done bool, err error)

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 Uses

type IntervalFactory interface {
    New(interval time.Duration) WaitFunc
}

IntervalFactory is a factory that can produce WaitFuncs that wait for the given interval.

func DefaultIntervalFactory Uses

func DefaultIntervalFactory() IntervalFactory

DefaultIntervalFactory returns the default IntervalFactory.

func NewIntervalFactory Uses

func NewIntervalFactory(contextOps utilcontext.Ops) IntervalFactory

NewIntervalFactory returns a new IntervalFactory using the given utilcontext.Ops.

type IntervalFactoryFunc Uses

type IntervalFactoryFunc func(interval time.Duration) WaitFunc

IntervalFactoryFunc is a function that implements IntervalFactory.

func (IntervalFactoryFunc) New Uses

func (f IntervalFactoryFunc) New(interval time.Duration) WaitFunc

New implements IntervalFactory.

type Ops Uses

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
    // Until 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 Uses

func DefaultOps() Ops

DefaultOps returns the default Ops with the DefaultIntervalFactory, DefaultErrorAggregatorFactory and utilcontext.DefaultOps.

func NewOps Uses

func NewOps(intervalFactory IntervalFactory, errorAggregatorFactory ErrorAggregatorFactory, contextOps utilcontext.Ops) Ops

NewOps returns the new ops with the given IntervalFactory, ErrorAggregatorFactory and utilcontext.Ops.

type WaitFunc Uses

type WaitFunc func(context.Context) (context.Context, context.CancelFunc)

WaitFunc is a function that given context of a retry execution, returns a context that is closed after a predefined wait amount.

Package retry imports 4 packages (graph) and is imported by 17 packages. Updated 2019-06-06. Refresh now. Tools for package owners.