exec

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingExecFn     = errors.New("no exec function provided")
	ErrMissingFallbackFn = errors.New("no fallback function provided")
)

Functions

This section is empty.

Types

type Error

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

Error holds none or multiple errors that can happen during execution.

func (*Error) AddErr

func (e *Error) AddErr(err error)

AddErr appends an error to the error slice of Error.

func (*Error) Error

func (e *Error) Error() string

Error implements the standard error interface.

type NewRetryableExecutorMockT

type NewRetryableExecutorMockT interface {
	mock.TestingT
	Cleanup(func())
}

type Opts

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

Opts holds the configurable options for a RetryableExecutor.

func NewDefaultExecOpts

func NewDefaultExecOpts() *Opts

NewDefaultExecOpts creates the default Opts.

type OptsFn

type OptsFn func(opts *Opts)

OptsFn is function that operate on Opts.

func WithMaxRetryCount

func WithMaxRetryCount(maxRetryCount uint) OptsFn

WithMaxRetryCount sets the max retry count.

Note that a default value is provided if the provided count is 0.

func WithRetryOnFallBackError

func WithRetryOnFallBackError(retryOnFallbackError bool) OptsFn

WithRetryOnFallBackError sets the retryOnFallbackError flag.

func WithRetryTimeout

func WithRetryTimeout(retryTimeout time.Duration) OptsFn

WithRetryTimeout sets the retry timeout.

type RetryableExecutor

type RetryableExecutor[T any] interface {
	ExecWithFallback(execFn func() (T, error), fallbackFn func() error) (T, error)
}

RetryableExecutor is the interface used for executing a closure and its fallback if the initial execution fails.

The interface is generic over type T which represents the return value of the closure.

func NewRetryableExecutor

func NewRetryableExecutor[T any](opts ...OptsFn) RetryableExecutor[T]

NewRetryableExecutor creates a new RetryableExecutor.

type RetryableExecutorMock

type RetryableExecutorMock[T interface{}] struct {
	mock.Mock
}

RetryableExecutorMock is an autogenerated mock type for the RetryableExecutor type

func NewRetryableExecutorMock

func NewRetryableExecutorMock[T interface{}](t NewRetryableExecutorMockT) *RetryableExecutorMock[T]

NewRetryableExecutorMock creates a new instance of RetryableExecutorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*RetryableExecutorMock[T]) ExecWithFallback

func (_m *RetryableExecutorMock[T]) ExecWithFallback(execFn func() (T, error), fallbackFn func() error) (T, error)

ExecWithFallback provides a mock function with given fields: execFn, fallbackFn

Jump to

Keyboard shortcuts

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