Plexus.Budget.Accounts (Plexus v0.1.0)

Copy Markdown View Source

Run-local hierarchical credit grants.

Grants reserve finite credits in the parent up front. Reservations in a child spend its grant, sibling transfers move only unused credit, and closing a leaf returns unused credit while retaining consumed work in its parent. The root is the run's atomic budget; ordinary measurements keep that fast path. Scoped credit management is serialized within this run, never globally.

Summary

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(run_id, account)

@spec close(term(), term()) :: :ok | {:error, term()}

grant(run_id, parent, child, limits)

@spec grant(term(), term(), term(), keyword() | map()) :: :ok | {:error, term()}

refund(run_id, account, meter, amount)

@spec refund(term(), term(), Plexus.Budget.meter(), non_neg_integer()) ::
  :ok | {:error, term()}

reserve(run_id, account, meter, amount)

@spec reserve(term(), term(), Plexus.Budget.meter(), non_neg_integer()) ::
  :ok | {:error, term()}

snapshot(run_id)

@spec snapshot(term()) :: map()

start_link(opts)

transfer(run_id, from, to, meter, amount)

@spec transfer(term(), term(), term(), Plexus.Budget.meter(), non_neg_integer()) ::
  :ok | {:error, term()}