Documentation ¶
Index ¶
- Constants
- func AddRequestCancelCheck(check RequestCanceledCheck)
- func IsClientAwaitHeadersTimeoutError(err error) bool
- func IsConnectionError(err error) bool
- func IsErrMaxAttemptsExceeded(err error) bool
- func IsErrMaxElapsedTimeExceeded(err error) bool
- func IsRequestCanceled(err error) bool
- func IsTimeoutError(err error) bool
- func IsTlsHandshakeTimeoutError(err error) bool
- func IsUsedClosedConnectionError(err error) bool
- func NewExponentialBackOff(settings *BackoffSettings) *backoff.ExponentialBackOff
- func NewTestHttpClient(timeout time.Duration, trips Trips) http.Client
- func WithManualCancelContext(parentCtx context.Context) (context.Context, context.CancelFunc)
- type BackoffExecutor
- type BackoffSettings
- type DefaultExecutor
- type ErrAttemptsExceeded
- type ErrMaxElapsedTimeExceeded
- type ErrorChecker
- type ErrorType
- func CheckClientAwaitHeaderTimeoutError(_ interface{}, err error) ErrorType
- func CheckConnectionError(_ interface{}, err error) ErrorType
- func CheckRequestCanceled(_ interface{}, err error) ErrorType
- func CheckTimeoutError(_ interface{}, err error) ErrorType
- func CheckTlsHandshakeTimeoutError(_ interface{}, err error) ErrorType
- func CheckUsedClosedConnectionError(_ interface{}, err error) ErrorType
- type Executable
- type ExecutableResource
- type Executor
- type Notify
- type RequestCanceledCheck
- type StopFunc
- type TestRoundTripper
- type Trip
- type Trips
Constants ¶
const RequestCanceledError = requestCanceledError("RequestCanceled")
Variables ¶
This section is empty.
Functions ¶
func AddRequestCancelCheck ¶
func AddRequestCancelCheck(check RequestCanceledCheck)
func IsConnectionError ¶
func IsRequestCanceled ¶
IsRequestCanceled checks if the given error was (only) caused by a canceled context - if there is any other error contained in it, we return false. Thus, if IsRequestCanceled returns true, you can (and should) ignore the error and stop processing instead.
func IsTimeoutError ¶
func NewExponentialBackOff ¶
func NewExponentialBackOff(settings *BackoffSettings) *backoff.ExponentialBackOff
func WithManualCancelContext ¶
WithManualCancelContext is similar to context.WithCancel, but it only cancels the returned context once the cancel function has been called. Cancellation of the parent context is not automatically propagated to the child context.
Types ¶
type BackoffExecutor ¶
type BackoffExecutor struct {
// contains filtered or unexported fields
}
func NewBackoffExecutor ¶
func NewBackoffExecutor(logger log.Logger, res *ExecutableResource, settings *BackoffSettings, checks []ErrorChecker, notifier ...Notify) *BackoffExecutor
func (*BackoffExecutor) Execute ¶
func (e *BackoffExecutor) Execute(ctx context.Context, f Executable, notifier ...Notify) (interface{}, error)
type BackoffSettings ¶
type BackoffSettings struct { CancelDelay time.Duration `cfg:"cancel_delay"` InitialInterval time.Duration `cfg:"initial_interval" default:"50ms"` MaxAttempts int `cfg:"max_attempts" default:"10"` MaxElapsedTime time.Duration `cfg:"max_elapsed_time" default:"10m"` MaxInterval time.Duration `cfg:"max_interval" default:"10s"` }
func ReadBackoffSettings ¶
func ReadBackoffSettings(config cfg.Config, paths ...string) BackoffSettings
type DefaultExecutor ¶
type DefaultExecutor struct{}
func NewDefaultExecutor ¶
func NewDefaultExecutor() *DefaultExecutor
func (DefaultExecutor) Execute ¶
func (e DefaultExecutor) Execute(ctx context.Context, f Executable, notifier ...Notify) (interface{}, error)
type ErrAttemptsExceeded ¶
type ErrAttemptsExceeded struct { Resource *ExecutableResource Attempts int DurationTook time.Duration Err error }
func NewErrAttemptsExceeded ¶
func NewErrAttemptsExceeded(resource *ExecutableResource, attempts int, durationTook time.Duration, err error) *ErrAttemptsExceeded
func (*ErrAttemptsExceeded) Error ¶
func (e *ErrAttemptsExceeded) Error() string
func (*ErrAttemptsExceeded) Unwrap ¶
func (e *ErrAttemptsExceeded) Unwrap() error
type ErrMaxElapsedTimeExceeded ¶
type ErrMaxElapsedTimeExceeded struct { Resource *ExecutableResource Attempts int DurationTook time.Duration DurationMax time.Duration Err error }
func NewErrMaxElapsedTimeExceeded ¶
func NewErrMaxElapsedTimeExceeded(resource *ExecutableResource, attempts int, durationTook time.Duration, durationMax time.Duration, err error) *ErrMaxElapsedTimeExceeded
func (ErrMaxElapsedTimeExceeded) Error ¶
func (e ErrMaxElapsedTimeExceeded) Error() string
func (ErrMaxElapsedTimeExceeded) Unwrap ¶
func (e ErrMaxElapsedTimeExceeded) Unwrap() error
type ErrorChecker ¶
type ErrorType ¶
type ErrorType int
const ( // We don't know yet, let the other error checkers decide about this error. If the error is // not marked retryable by another checker, we will not retry it. ErrorTypeUnknown ErrorType = iota // Stop retrying, the error was actually a "success" and needs to be propagated to the caller // ("success" meaning something e.g. was not found, but will not magically appear just because // we retry a few more times) ErrorTypeOk // Immediately stop retrying and return this error to the caller ErrorTypePermanent // Retry the execution of the action ErrorTypeRetryable )
func CheckConnectionError ¶
func CheckRequestCanceled ¶
func CheckTimeoutError ¶
type Executable ¶
type ExecutableResource ¶
func (ExecutableResource) String ¶
func (r ExecutableResource) String() string
type Executor ¶
type Executor interface {
Execute(ctx context.Context, f Executable, notifier ...Notify) (interface{}, error)
}
func NewExecutor ¶
func NewExecutor(logger log.Logger, res *ExecutableResource, settings *BackoffSettings, checks []ErrorChecker, notifier ...Notify) Executor
type RequestCanceledCheck ¶
type StopFunc ¶
type StopFunc func()
func WithDelayedCancelContext ¶
func WithDelayedCancelContext(parentCtx context.Context, delay time.Duration) (context.Context, StopFunc)
WithDelayedCancelContext creates a context which propagates the cancellation of the parent context after a fixed delay to the returned context. Call the returned StopFunc function to release resources associated with the returned context once you no longer need it. Calling stop never returns before all resources have been released, so after Stop returns, the context will not experience a delayed cancel anymore (however, if the parent context was already canceled the moment you called stop, the child context will immediately get canceled).
func WithStoppableDeadlineContext ¶
func WithStoppableDeadlineContext(parentCtx context.Context, deadline time.Time) (context.Context, StopFunc)
WithStoppableDeadlineContext is similar to context.WithDeadline. However, while context.WithDeadline cancels the context when you call the returned context.CancelFunc, WithStoppableDeadlineContext does not cancel the context if it is not yet canceled once you stop it.
type TestRoundTripper ¶
type TestRoundTripper struct {
// contains filtered or unexported fields
}
func NewTestRoundTripper ¶
func NewTestRoundTripper(trips ...Trip) *TestRoundTripper