backoff

package module
v0.0.0-...-657194c 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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	Config Conf
	Fn     Fn
}

func New

func New(fn func(ctx context.Context) error, c Conf) Backoff

New backoff instance with default values

func NewInstance

func NewInstance(fn func(ctx context.Context) error, conf Conf) Backoff

NewInstance creates instance without default configs. Running with all zero values will lead to unexpected behavior. Consider to use New or set values by hand.

func (Backoff) NextWait

func (b Backoff) NextWait(wait time.Duration) time.Duration

func (Backoff) Run

func (b Backoff) Run(ctx context.Context) error

type Conf

type Conf struct {
	Logger          Logger
	DisableRecovery bool

	// HealthChecker func will be called while waiting for Fn returning errors.
	// Once Fn returned anything, the context passed to NewHealthChecker will be canceled.
	// If error chan return nil, wait time will be reset. Otherwise, the context passed
	// to Fn and HealthChecker will be canceled.
	HealthChecker HealthChecker

	// InitialDuration means initial wait time, default 1 second
	InitialDuration time.Duration
	// MaxDuration means maximum retry wait time, default 20 minutes
	MaxDuration time.Duration
	// MaxRetry, default unlimited
	MaxRetry uint

	// ExponentFactor default 1
	ExponentFactor   int
	InterConstFactor time.Duration
	OuterConstFactor time.Duration
}

type CtxCancelFn

type CtxCancelFn struct {
	CtxStructKey[CtxCancelFn, context.CancelFunc]
}

type CtxResetWait

type CtxResetWait struct {
	CtxStructKey[CtxResetWait, chan struct{}]
}

type CtxStructKey

type CtxStructKey[Key, Value any] struct{}

func (CtxStructKey[Key, Value]) Get

func (CtxStructKey[Key, Value]) Get(ctx context.Context) (Value, bool)

func (CtxStructKey[Key, Value]) Must

func (c CtxStructKey[Key, Value]) Must(ctx context.Context) Value

func (CtxStructKey[Key, Value]) Set

func (CtxStructKey[Key, Value]) Set(ctx context.Context, value Value) context.Context

type ErrorAlreadyRunning

type ErrorAlreadyRunning struct{}

func (ErrorAlreadyRunning) Error

func (e ErrorAlreadyRunning) Error() string

type ErrorKeywordNotFound

type ErrorKeywordNotFound struct {
	Keyword string
}

func (ErrorKeywordNotFound) Error

func (e ErrorKeywordNotFound) Error() string

type ErrorMaxRetryExceeded

type ErrorMaxRetryExceeded struct {
	LastError error
}

func (ErrorMaxRetryExceeded) Error

func (e ErrorMaxRetryExceeded) Error() string

type ErrorPanic

type ErrorPanic struct {
	Reason any
	Stack  string
}

func (ErrorPanic) Error

func (e ErrorPanic) Error() string

type ErrorUnexpectedHttpStatus

type ErrorUnexpectedHttpStatus struct {
	HttpStatus int
}

func (ErrorUnexpectedHttpStatus) Error

type Fn

type Fn func(ctx context.Context) error

type HealthChecker

type HealthChecker func(ctx context.Context) <-chan error

type HttpProbeHealthCheckConfig

type HttpProbeHealthCheckConfig struct {
	// If http.Client is not nil, some config will not take effect.
	Client  *http.Client
	Timeout time.Duration

	FollowRedirect bool

	Method string
	URL    string
	Header http.Header
	// HttpStatusCode determines which HTTP code is
	// considered successful. If HttpStatusCode is 0,
	// any status between 200 and 299 is considered a success.
	HttpStatusCode int
	// If Keyword is empty, the health check will pass only
	// when the response body contains the keyword.
	// The keyword must not contain line breaks.
	Keyword string
}

type Logger

type Logger interface {
	log.FieldLogger
	WithContext(ctx context.Context) *log.Entry
}

type ProbeHealthCheckFn

type ProbeHealthCheckFn func(ctx context.Context) error

func NewTcpProbeHealthCheckFn

func NewTcpProbeHealthCheckFn(conf TcpProbeHealthCheckConfig) ProbeHealthCheckFn

type ProbeHealthCheckerConfig

type ProbeHealthCheckerConfig struct {
	Logger           log.FieldLogger
	CheckInterval    time.Duration
	InitialDelay     time.Duration
	SuccessThreshold int
	FailureThreshold int
}

type TcpProbeHealthCheckConfig

type TcpProbeHealthCheckConfig struct {
	Addr    string
	Timeout time.Duration
	Dialer  net.Dialer
}

Jump to

Keyboard shortcuts

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