Portable limits and consumption counters for one operational loop.
A missing limit means that dimension is not bounded. Budget checks happen before a Runner is created and again after its committed result.
Summary
Functions
Consumes one or more budget dimensions.
Returns the first exhausted dimension, if any.
Builds a validated budget from a struct, map, keyword list or nil.
Returns the remaining value for a bounded dimension.
Validates the budget's limits, consumption counters, timestamps and portability.
Same as validate/1 but returns the budget, raising ArgumentError when invalid.
Types
@type dimension() :: :steps | :attempts | :retries | :duration_ms | :pages | :cost
@type t() :: %Spectre.Operation.Budget{ consumed: %{optional(atom()) => non_neg_integer() | number()}, deadline_at: non_neg_integer() | nil, limits: %{optional(dimension()) => non_neg_integer() | number() | nil}, resources: map(), started_at: non_neg_integer() }
Functions
Consumes one or more budget dimensions.
@spec exhausted(t(), non_neg_integer()) :: nil | {dimension(), number(), number()}
Returns the first exhausted dimension, if any.
@spec new(t() | map() | keyword() | nil, non_neg_integer()) :: t()
Builds a validated budget from a struct, map, keyword list or nil.
nil yields an unbounded budget. Limits may be given at the top level or under
:limits; a :duration_ms limit derives deadline_at from now unless a
deadline is given explicitly. Raises ArgumentError when the result is invalid.
Returns the remaining value for a bounded dimension.
Validates the budget's limits, consumption counters, timestamps and portability.
Returns :ok, or {:error, reason} naming the first invalid field.
Same as validate/1 but returns the budget, raising ArgumentError when invalid.