ExAgent.UsageLimits.Budget.ETS (ExAgent v3.0.0)

View Source

A supervised local spend account with a read-only ETS balance.

Stability — Stable.

{ExAgent.UsageLimits.Budget.ETS,
 name: MyApp.BudgetLedger, limit_cents: 500, window_ms: :timer.hours(24)}

Use {ExAgent.UsageLimits.Budget.ETS, MyApp.BudgetLedger} as the budget's adapter. Windows align to the Unix epoch. Closed charges count in their reservation window. Outstanding holds count across windows, including ones with an unknown charge. The owner serializes mutations. Balance reads use one committed snapshot directly from ETS.

A local account is volatile. Its owner and table must stay alive to keep holds, receipts and threshold claims. Each owner keeps up to :max_receipts receipts (10,000 by default) and refuses further admissions when full. Keeping the receipts preserves duplicate protection and idempotent settlement. Use PostgreSQL for durable accounts across replicas.

Opt into candidate threshold events with :thresholds, a list of distinct whole percentages from 1 to 100. A positive confirmed charge can trigger each reached threshold once per original window in this account.

Summary

Functions

Builds a child specification with an ID scoped to the account name.

Starts a linked local account. The owner and the table use the given name.

Functions

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Builds a child specification with an ID scoped to the account name.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a linked local account. The owner and the table use the given name.