Rheo.Backoff (rheo v1.0.0)

Copy Markdown View Source

Exponential backoff schedule shared by Rheo.Group and Rheo.Producer.

A runtime holds the current delay in its state (0 when healthy). Each consecutive fetch failure doubles the delay from min_ms/0 up to max_ms/0; a successful fetch resets it to 0. The schedule is fixed (100 ms … 5_000 ms) so coordinators share the same pacing without per-instance config.

Examples

iex> Rheo.Backoff.next(0)
100

iex> Rheo.Backoff.next(100)
200

iex> Rheo.Backoff.next(4_000)
5000

iex> Rheo.Backoff.min_ms()
100

iex> Rheo.Backoff.max_ms()
5000

Summary

Functions

Largest delay in milliseconds.

Smallest non-zero delay in milliseconds.

Next delay after current_ms.

Functions

max_ms()

@spec max_ms() :: pos_integer()

Largest delay in milliseconds.

Examples

iex> Rheo.Backoff.max_ms()
5000

Returns

5000.

min_ms()

@spec min_ms() :: pos_integer()

Smallest non-zero delay in milliseconds.

Examples

iex> Rheo.Backoff.min_ms()
100

Returns

100.

next(current_ms)

@spec next(non_neg_integer()) :: pos_integer()

Next delay after current_ms.

Pass 0 when there is no backoff yet (healthy). Otherwise doubles current_ms and clamps at max_ms/0.

Examples

iex> Rheo.Backoff.next(0)
100

iex> Rheo.Backoff.next(100)
200

iex> Rheo.Backoff.next(Rheo.Backoff.max_ms())
5000

Returns

A positive integer delay in milliseconds.