retry

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultFailAfterMaxAttempts bool = false
View Source
const DefaultMaxAttempts int = 3
View Source
const DefaultWaitDuration = time.Millisecond * 500

Variables

This section is empty.

Functions

func DecorateConsumer

func DecorateConsumer[T any](retry Retry, fn func(T) error) func(T) error

func DecorateFunction

func DecorateFunction[T any, R any](retry Retry, fn func(T) (R, error)) func(T) (R, error)

func DecorateRunnable

func DecorateRunnable(retry Retry, fn func() error) func() error

func DecorateSupplier

func DecorateSupplier[T any](retry Retry, fn func() (T, error)) func() (T, error)

func DefaultFailureResultPredicate added in v0.3.0

func DefaultFailureResultPredicate(_ any, err error) bool

func DefaultWaitIntervalFunction

func DefaultWaitIntervalFunction(_ int) time.Duration

Types

type Config

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

func (*Config) String

func (config *Config) String() string

type ConfigBuilder

type ConfigBuilder func(*Config)

func WithFailAfterMaxAttempts

func WithFailAfterMaxAttempts(failAfterMaxAttempts bool) ConfigBuilder

func WithFailureResultPredicate added in v0.3.0

func WithFailureResultPredicate(predicate func(any, error) bool) ConfigBuilder

func WithMaxAttempts

func WithMaxAttempts(maxAttempts int) ConfigBuilder

func WithWaitIntervalFunction

func WithWaitIntervalFunction(function func(int) time.Duration) ConfigBuilder

type ErrorEvent added in v0.4.1

type ErrorEvent interface {
	Event
}

type Event

type Event interface {
	fmt.Stringer
	RetryName() string
	CreationTime() time.Time
	EventType() EventType
	NumOfAttempts() int
	RetVal() any
	RetErr() error
}

type EventListener

type EventListener interface {
	OnSuccessFunc(func(SuccessEvent)) EventListener
	OnRetryFunc(func(RetryEvent)) EventListener
	OnErrorFunc(func(ErrorEvent)) EventListener
	DismissSuccessFunc(func(SuccessEvent)) EventListener
	DismissRetryFunc(func(RetryEvent)) EventListener
	DismissErrorFunc(func(ErrorEvent)) EventListener

	OnSuccess(fn.Consumer[SuccessEvent]) EventListener
	OnRetry(fn.Consumer[RetryEvent]) EventListener
	OnError(fn.Consumer[ErrorEvent]) EventListener
	DismissSuccess(fn.Consumer[SuccessEvent]) EventListener
	DismissRetry(fn.Consumer[RetryEvent]) EventListener
	DismissError(fn.Consumer[ErrorEvent]) EventListener
}

type EventType

type EventType string
const (
	SUCCESS EventType = "SUCCESS"
	RETRY   EventType = "RETRY"
	ERROR   EventType = "ERROR"
)

type MaxRetriesExceeded

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

func (*MaxRetriesExceeded) Error

func (e *MaxRetriesExceeded) Error() string

type Metrics

type Metrics interface {
	NumberOfSuccessfulCallsWithoutRetryAttempt() uint64
	NumberOfSuccessfulCallsWithRetryAttempt() uint64
	NumberOfFailedCallsWithoutRetryAttempt() uint64
	NumberOfFailedCallsWithRetryAttempt() uint64
}

type Retry

type Retry interface {
	Name() string
	Metrics() Metrics
	EventListener() EventListener
	Execute(func() (any, error)) (any, error)
}

func NewRetry

func NewRetry(name string, configs ...ConfigBuilder) Retry

type RetryEvent added in v0.4.1

type RetryEvent interface {
	Event
	WaitDuration() time.Duration
}

type SuccessEvent added in v0.4.1

type SuccessEvent interface {
	Event
}

Jump to

Keyboard shortcuts

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