Documentation
¶
Index ¶
- Constants
- Variables
- func SetGlobalInterruptChecker(checker GlobalInterruptChecker)
- type BreakPredicate
- type GlobalInterruptChecker
- type Loop
- func NewLoop(name string, attemptsQuantity int, wait time.Duration) *Loop
- func NewLoopWithParams(params Params) *Loop
- func NewLoopWithParamsOpts(opts ...ParamsBuilderOpt) *Loop
- func NewSilentLoop(name string, attemptsQuantity int, wait time.Duration) *Loop
- func NewSilentLoopWithParams(params Params) *Loop
- func NewSilentLoopWithParamsOpts(opts ...ParamsBuilderOpt) *Loop
- func (l *Loop) BreakIf(pred BreakPredicate) *Loop
- func (l *Loop) Run(task func() error) error
- func (l *Loop) RunContext(ctx context.Context, task func() error) error
- func (l *Loop) WithInterruptable(flag bool) *Loop
- func (l *Loop) WithLogger(lg *slog.Logger) *Loop
- func (l *Loop) WithShowError(flag bool) *Loop
- type Params
- type ParamsBuilderOpt
- func AttemptsWithWaitOpts(attempts int, wait time.Duration) []ParamsBuilderOpt
- func WithAttempts(attempts int) ParamsBuilderOpt
- func WithLogger(l *slog.Logger) ParamsBuilderOpt
- func WithName(format string, args ...any) ParamsBuilderOpt
- func WithWait(wait time.Duration) ParamsBuilderOpt
- func WithWhitelist(errs ...error) ParamsBuilderOpt
Constants ¶
const (
NotSetName = "Name not set"
)
Variables ¶
var InTestEnvironment = false
InTestEnvironment, when set, collapses every loop to a single, wait-free attempt so tests exercising retry-driven code don't pay real wall-clock time.
Functions ¶
func SetGlobalInterruptChecker ¶
func SetGlobalInterruptChecker(checker GlobalInterruptChecker)
Types ¶
type BreakPredicate ¶
func IsErr ¶
func IsErr(err error) BreakPredicate
type GlobalInterruptChecker ¶
type GlobalInterruptChecker func() bool
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
Loop retries a task function until it succeeded with number of attempts and delay between runs are adjustable.
func NewLoop ¶
NewLoop create Loop with features: - it is "verbose" loop — it prints messages through logboek. - this loop is interruptable by the signal watcher in tomb package. Deprecated: use NewLoopWithParams in futures versions NewLoop will take Params
func NewLoopWithParams ¶
func NewLoopWithParamsOpts ¶
func NewLoopWithParamsOpts(opts ...ParamsBuilderOpt) *Loop
func NewSilentLoop ¶
NewSilentLoop create Loop with features: - it is "silent" loop — no messages are printed through logboek. - this loop is not interruptable by the signal watcher in tomb package. Deprecated: use NewSilentLoopWithParams in futures versions NewSilentLoop will take Params
func NewSilentLoopWithParams ¶
func NewSilentLoopWithParamsOpts ¶
func NewSilentLoopWithParamsOpts(opts ...ParamsBuilderOpt) *Loop
func (*Loop) BreakIf ¶
func (l *Loop) BreakIf(pred BreakPredicate) *Loop
func (*Loop) RunContext ¶
RunContext retries a task like Run but breaks if context done.
func (*Loop) WithInterruptable ¶
func (*Loop) WithShowError ¶
type Params ¶
type Params interface {
Name() string
Attempts() int
Wait() time.Duration
Logger() *slog.Logger
Whitelisted() bool
WhitelistedErrors() []error
Clone(overrides ...ParamsBuilderOpt) Params
}
func NewEmptyParams ¶
func NewEmptyParams(opts ...ParamsBuilderOpt) Params
func SafeCloneOrNewParams ¶
func SafeCloneOrNewParams(p Params, opts ...ParamsBuilderOpt) Params
type ParamsBuilderOpt ¶
type ParamsBuilderOpt func(Params)
func AttemptsWithWaitOpts ¶
func AttemptsWithWaitOpts(attempts int, wait time.Duration) []ParamsBuilderOpt
func WithAttempts ¶
func WithAttempts(attempts int) ParamsBuilderOpt
func WithLogger ¶
func WithLogger(l *slog.Logger) ParamsBuilderOpt
func WithName ¶
func WithName(format string, args ...any) ParamsBuilderOpt
func WithWait ¶
func WithWait(wait time.Duration) ParamsBuilderOpt
func WithWhitelist ¶ added in v0.22.0
func WithWhitelist(errs ...error) ParamsBuilderOpt
WithWhitelist marks the loop as whitelisted and sets the errors that are allowed to be retried. If errs is empty, retry behaves as if whitelist was never set (backward compatible). If errs is not empty, a returned error that does not match any whitelisted error (via errors.Is) stops the loop immediately instead of retrying.