pub struct RateLeaseKernel { /* private fields */ }Expand description
An in-process registry of RateLeases, keyed by an opaque subject string
(the §72.c dispatch gate composes the key from the budget’s scope + the
effect + the quota kind, e.g. "daemon:Outbound:Tool(TelnyxCall):rate"). This
is the OSS single-replica reference; the §72.e enterprise layer binds the
per-tenant Redis RateLimiter for multi-replica enforcement.
Implementations§
Source§impl RateLeaseKernel
impl RateLeaseKernel
pub fn new() -> Self
Sourcepub fn register(&mut self, key: impl Into<String>, lease: RateLease)
pub fn register(&mut self, key: impl Into<String>, lease: RateLease)
Register (or replace) the lease for key.
Sourcepub fn try_acquire(&mut self, key: &str, now: DateTime<Utc>) -> AcquireOutcome
pub fn try_acquire(&mut self, key: &str, now: DateTime<Utc>) -> AcquireOutcome
Attempt to consume one token from the lease at key. A key with no
registered lease is unbudgeted ⇒ always AcquireOutcome::Granted
(an effect with no declared quota is not rate-limited).
Sourcepub fn try_acquire_all(
&mut self,
keys: &[String],
now: DateTime<Utc>,
) -> AcquireOutcome
pub fn try_acquire_all( &mut self, keys: &[String], now: DateTime<Utc>, ) -> AcquireOutcome
Attempt to consume one token from EVERY lease in keys, all-or-none:
consumes from all only if all have a token (so a per-hour rate and a
per-day max on the same tool both gate the call without a partial
consumption when one is exhausted). Returns AcquireOutcome::Denied with
the LATEST retry_at among the exhausted leases (the binding constraint —
you must wait for the slowest). An empty keys (an unbudgeted effect) is
granted. Unknown keys are skipped (treated as unbudgeted).
Sourcepub fn available(&self, key: &str, now: DateTime<Utc>) -> Option<f64>
pub fn available(&self, key: &str, now: DateTime<Utc>) -> Option<f64>
Tokens currently available at key (None if unregistered).
Sourcepub fn tick(&mut self, now: DateTime<Utc>)
pub fn tick(&mut self, now: DateTime<Utc>)
Housekeeping pass — refill/roll every registered lease to now so
available snapshots are fresh. The refilling analogue of the lease
kernel’s sweep. Acquisition does not depend on this (refill is lazy).
Sourcepub fn snapshot(&self) -> Vec<(String, RateLeaseSnapshot)>
pub fn snapshot(&self) -> Vec<(String, RateLeaseSnapshot)>
§Fase 72.e — snapshot every lease’s state as (key, snapshot) pairs for
persistence. Deterministic order (sorted by key).
Sourcepub fn restore(&mut self, snaps: &[(String, RateLeaseSnapshot)])
pub fn restore(&mut self, snaps: &[(String, RateLeaseSnapshot)])
§Fase 72.e — restore lease states from (key, snapshot) pairs. Keys with
no registered lease are skipped (a quota dropped from a re-budgeted daemon).
Trait Implementations§
Source§impl Default for RateLeaseKernel
impl Default for RateLeaseKernel
Source§fn default() -> RateLeaseKernel
fn default() -> RateLeaseKernel
Auto Trait Implementations§
impl Freeze for RateLeaseKernel
impl RefUnwindSafe for RateLeaseKernel
impl Send for RateLeaseKernel
impl Sync for RateLeaseKernel
impl Unpin for RateLeaseKernel
impl UnsafeUnpin for RateLeaseKernel
impl UnwindSafe for RateLeaseKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more