pub struct BudgetTracker { /* private fields */ }Expand description
In-memory per-task budget tracker.
Reconstructed from WAL events at bootstrap via BudgetTracker::allocate
and BudgetTracker::consume calls. The dispatch loop updates the tracker
each tick as WorkerResults arrive.
Implementations§
Source§impl BudgetTracker
impl BudgetTracker
Sourcepub fn allocate(
&mut self,
task_id: TaskId,
dimension: BudgetDimension,
limit: u64,
)
pub fn allocate( &mut self, task_id: TaskId, dimension: BudgetDimension, limit: u64, )
Registers a budget allocation for a task/dimension pair.
If an allocation already exists for this pair, it is replaced (re-allocation).
Sourcepub fn consume(
&mut self,
task_id: TaskId,
dimension: BudgetDimension,
amount: u64,
) -> ConsumeResult
pub fn consume( &mut self, task_id: TaskId, dimension: BudgetDimension, amount: u64, ) -> ConsumeResult
Records consumption and returns whether the budget was exhausted by this call.
No-ops if no allocation exists for the (task, dimension) pair.
Sourcepub fn replenish(
&mut self,
task_id: TaskId,
dimension: BudgetDimension,
new_limit: u64,
)
pub fn replenish( &mut self, task_id: TaskId, dimension: BudgetDimension, new_limit: u64, )
Replenishes a budget: sets new limit and clears the exhausted flag.
Sourcepub fn is_exhausted(&self, task_id: TaskId, dimension: BudgetDimension) -> bool
pub fn is_exhausted(&self, task_id: TaskId, dimension: BudgetDimension) -> bool
Returns true if the given dimension budget is exhausted for this task.
Sourcepub fn is_any_exhausted(&self, task_id: TaskId) -> bool
pub fn is_any_exhausted(&self, task_id: TaskId) -> bool
Returns true if ANY dimension budget is exhausted for this task.
Sourcepub fn remaining(
&self,
task_id: TaskId,
dimension: BudgetDimension,
) -> Option<u64>
pub fn remaining( &self, task_id: TaskId, dimension: BudgetDimension, ) -> Option<u64>
Returns the remaining budget for a (task, dimension) pair.
Returns None if no allocation exists.
Sourcepub fn threshold_pct(
&self,
task_id: TaskId,
dimension: BudgetDimension,
) -> Option<u8>
pub fn threshold_pct( &self, task_id: TaskId, dimension: BudgetDimension, ) -> Option<u8>
Returns consumed amount as a percentage of the limit (0-100).
Returns None if no allocation exists.
Sourcepub fn get(
&self,
task_id: TaskId,
dimension: BudgetDimension,
) -> Option<&BudgetState>
pub fn get( &self, task_id: TaskId, dimension: BudgetDimension, ) -> Option<&BudgetState>
Returns the state for a (task, dimension) pair.