backoff

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package backoff computes jittered retry delays, fixed step schedules and poll intervals for the event-sourcing, scheduler and inbox runtimes.

Jitter only ever shortens a delay, so a configured delay is always an upper bound.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Poll

func Poll(interval time.Duration, src Source) time.Duration

Poll returns interval jittered down by up to a fifth, so that pods polling the same table spread out.

Types

type Retry

type Retry struct {
	// MaxAttempts is the total number of attempts, including the first.
	MaxAttempts int
	// Base is the delay after the first failed attempt.
	Base time.Duration
	// Max caps every delay.
	Max time.Duration
}

Retry describes jittered exponential retry delays.

func (Retry) Delay

func (r Retry) Delay(failed int, src Source) (time.Duration, bool)

Delay returns the wait after failed attempts and before the next one. The exponential delay min(Base*2^(failed-1), Max) is jittered down by up to half. It reports false once failed reaches MaxAttempts or when failed is below 1.

type Source

type Source interface {
	// Int64N returns a value in [0, n).
	Int64N(n int64) int64
}

Source draws jitter. *rand.Rand from math/rand/v2 satisfies it; a nil Source uses the global math/rand/v2 generator.

type Steps

type Steps []time.Duration

Steps is a fixed delay schedule, such as Reactor auto-redrive or inbox retries.

func (Steps) Delay

func (s Steps) Delay(failed int, src Source) (time.Duration, bool)

Delay returns the step for the given number of failures, jittered down by up to a fifth. It reports false once the schedule is exhausted or when failed is below 1.

Jump to

Keyboard shortcuts

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