pub struct Governor {
pub waiting: BTreeMap<String, u64>,
/* private fields */
}Expand description
The governor: the instance scope + named sub-scopes.
Fields§
§waiting: BTreeMap<String, u64>Units currently waiting on the budget (for the gauge / status).
Implementations§
Source§impl Governor
impl Governor
pub fn new(budget: &Budget) -> Governor
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Whether any budget is configured at all (else admission is trivially ok).
Sourcepub fn ensure_scope(&mut self, key: &str, budget: &Budget)
pub fn ensure_scope(&mut self, key: &str, budget: &Budget)
Ensure a sub-scope exists (e.g. conversation:<id>, run:<id>).
pub fn drop_scope(&mut self, key: &str)
Sourcepub fn admit(
&mut self,
estimate: u64,
scopes: &[String],
now_ms: u64,
) -> Admission
pub fn admit( &mut self, estimate: u64, scopes: &[String], now_ms: u64, ) -> Admission
Ask to spend estimate tokens now, under the instance scope and the
named sub-scopes (scopes must exist via ensure_scope). On Ok the
estimate is reserved until Governor::settle / Governor::release.
Sourcepub fn settle(&mut self, reservation: u64, usage: Usage)
pub fn settle(&mut self, reservation: u64, usage: Usage)
Settle a reservation with the reported usage.
Sourcepub fn charge(&mut self, usage: Usage, scopes: &[String])
pub fn charge(&mut self, usage: Usage, scopes: &[String])
Charge usage that had no reservation (a child reported more calls than admissions, or admission is off).
Sourcepub fn release(&mut self, reservation: u64)
pub fn release(&mut self, reservation: u64)
Release a reservation without usage (the unit never ran).
Sourcepub fn restore(&mut self, v: &Value, now_ms: u64)
pub fn restore(&mut self, v: &Value, now_ms: u64)
Adopt restored counters (matching windows by unit; scopes by key when
they exist — a scope restored before ensure_scope is kept aside).
Sourcepub fn lifetime_used(&self) -> u64
pub fn lifetime_used(&self) -> u64
The instance-scope lifetime usage.
Sourcepub fn next_reset_ms(&self, now_ms: u64) -> Option<u64>
pub fn next_reset_ms(&self, now_ms: u64) -> Option<u64>
The earliest moment any exhausted instance window opens again.