retry

package
v1.78.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package retry is the backoff of every execution failure in the lifecycle and the Clock its deadlines are read with.

Index

Constants

View Source
const (
	Min = time.Second
	Max = 2 * time.Minute
)

Default bounds of a backoff: the delay doubles from Min up to Max. Max is every engine backoff's cap: a package recovers within it after a transient outage.

Variables

This section is empty.

Functions

func Arm

func Arm(t Timer, c Clock, at time.Time)

Arm sets t to fire at at on c, or stops it when at is zero. at is a deadline computed once, from the time the owner decided at; one that passed since fires at once.

func Earliest

func Earliest(now time.Time, backoffs ...Backoff) time.Time

Earliest returns the earliest deadline of backoffs after now; zero when none is. The owner's one wake timer fires then (Arm); a deadline of an attempt the owner no longer wants only costs one more decision.

Types

type Backoff

type Backoff struct {
	// Initial is the first delay instead of Min when set.
	Initial time.Duration
	// contains filtered or unexported fields
}

Backoff delays a retry of one failed attempt; any other attempt is not delayed. The key names the attempt (an operation and its Inputs, a configuration): new Inputs or a new configuration are never delayed by the backoff of an older attempt, and a failure of another key starts the delay again from the first delay. The zero value holds nothing and doubles from Min up to Max. Not safe for concurrent use: one loop owns it.

func (*Backoff) Failed

func (b *Backoff) Failed(key string, now time.Time) time.Time

Failed records a failure of key at now and returns until when a retry of key is held. The delay doubles while the same key keeps failing.

func (*Backoff) Holds

func (b *Backoff) Holds(key string, now time.Time) bool

Holds reports whether an attempt of key must still wait at now: only the key that failed last, and only before its deadline.

func (*Backoff) Succeeded

func (b *Backoff) Succeeded()

Succeeded forgets the failure, keeping Initial: the next failure starts from the first delay.

func (*Backoff) Until

func (b *Backoff) Until() time.Time

Until returns the deadline of the last failure; zero when nothing failed since the last success. The owner wakes at it to retry.

type Clock

type Clock interface {
	Now() time.Time
	NewTimer(d time.Duration) Timer
}

Clock is the time the package Reconciler, Current and Global decide and wait with: backoff deadlines, the update window, their wake timers. Tests drive it by hand.

func OrWall

func OrWall(c Clock) Clock

OrWall returns c, or Wall when c is nil.

type Timer

type Timer interface {
	C() <-chan time.Time
	Reset(d time.Duration) bool
	Stop() bool
}

Timer is a timer of a Clock (time.Timer semantics since Go 1.23: Reset and Stop need no drain).

type Wall

type Wall struct{}

Wall is the real clock, the default of every Deps.

func (Wall) NewTimer

func (Wall) NewTimer(d time.Duration) Timer

func (Wall) Now

func (Wall) Now() time.Time

Jump to

Keyboard shortcuts

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