exec

package
v0.33.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const RequestCanceledError = requestCanceledError("RequestCanceled")

Variables

This section is empty.

Functions

func AddRequestCancelCheck

func AddRequestCancelCheck(check RequestCanceledCheck)

func IsClientAwaitHeadersTimeoutError

func IsClientAwaitHeadersTimeoutError(err error) bool

func IsConnectionError

func IsConnectionError(err error) bool

func IsErrMaxAttemptsExceeded

func IsErrMaxAttemptsExceeded(err error) bool

func IsErrMaxElapsedTimeExceeded

func IsErrMaxElapsedTimeExceeded(err error) bool

func IsRequestCanceled

func IsRequestCanceled(err error) bool

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 IsTimeoutError(err error) bool

func IsTlsHandshakeTimeoutError

func IsTlsHandshakeTimeoutError(err error) bool

func IsUsedClosedConnectionError

func IsUsedClosedConnectionError(err error) bool

func NewExponentialBackOff

func NewExponentialBackOff(settings *BackoffSettings) *backoff.ExponentialBackOff

func NewTestHttpClient

func NewTestHttpClient(timeout time.Duration, trips Trips) http.Client

func WithManualCancelContext

func WithManualCancelContext(parentCtx context.Context) (context.Context, context.CancelFunc)

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 (ErrMaxElapsedTimeExceeded) Unwrap

func (e ErrMaxElapsedTimeExceeded) Unwrap() error

type ErrorChecker

type ErrorChecker func(result interface{}, err error) ErrorType

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 CheckClientAwaitHeaderTimeoutError

func CheckClientAwaitHeaderTimeoutError(_ interface{}, err error) ErrorType

func CheckConnectionError

func CheckConnectionError(_ interface{}, err error) ErrorType

func CheckRequestCanceled

func CheckRequestCanceled(_ interface{}, err error) ErrorType

func CheckTimeoutError

func CheckTimeoutError(_ interface{}, err error) ErrorType

func CheckTlsHandshakeTimeoutError

func CheckTlsHandshakeTimeoutError(_ interface{}, err error) ErrorType

func CheckUsedClosedConnectionError

func CheckUsedClosedConnectionError(_ interface{}, err error) ErrorType

type Executable

type Executable func(ctx context.Context) (interface{}, error)

type ExecutableResource

type ExecutableResource struct {
	Type string
	Name string
}

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 Notify added in v0.20.0

type Notify func(error, time.Duration)

type RequestCanceledCheck

type RequestCanceledCheck func(err error) bool

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

func (*TestRoundTripper) RoundTrip

func (t *TestRoundTripper) RoundTrip(request *http.Request) (*http.Response, error)

type Trip

type Trip struct {
	// contains filtered or unexported fields
}

func DoTrip

func DoTrip(duration time.Duration, err error) Trip

type Trips

type Trips []Trip

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL