pub struct Period {
pub id: u64,
/* private fields */
}Expand description
One idle period. Pure: every clock reading is passed in.
Fields§
§id: u64Implementations§
Source§impl Period
impl Period
Sourcepub fn start(
id: u64,
cfg: PeriodConfig,
fingerprint: u64,
last: &KeepWarmUsage,
evidence: TtlEvidence,
anchor: CacheAnchor,
now: Instant,
wall: SystemTime,
) -> Result<Period, PeriodEnd>
pub fn start( id: u64, cfg: PeriodConfig, fingerprint: u64, last: &KeepWarmUsage, evidence: TtlEvidence, anchor: CacheAnchor, now: Instant, wall: SystemTime, ) -> Result<Period, PeriodEnd>
Start a period at now (the session just went idle). last is the
usage of the turn’s last request; evidence what the session knows
about the TTL the server honours.
Sourcepub fn start_in_epoch(
id: u64,
cfg: PeriodConfig,
fingerprint: u64,
last: &KeepWarmUsage,
evidence: TtlEvidence,
anchor: CacheAnchor,
now: Instant,
wall: SystemTime,
carry: Option<&EpochCarry>,
) -> Result<Period, PeriodEnd>
pub fn start_in_epoch( id: u64, cfg: PeriodConfig, fingerprint: u64, last: &KeepWarmUsage, evidence: TtlEvidence, anchor: CacheAnchor, now: Instant, wall: SystemTime, carry: Option<&EpochCarry>, ) -> Result<Period, PeriodEnd>
start, continuing carry when the cache epoch has
not changed since an earlier period (see EpochCarry).
Sourcepub fn epoch_carry(&self) -> EpochCarry
pub fn epoch_carry(&self) -> EpochCarry
What the next period of this cache epoch continues from.
pub fn fingerprint(&self) -> u64
pub fn pings(&self) -> u32
pub fn ledger_usd(&self) -> f64
pub fn bound_usd(&self) -> f64
Sourcepub fn worst_next_usd(&self) -> f64
pub fn worst_next_usd(&self) -> f64
Read-path worst case of the next ping (cache hit, max_tokens of
output): what the ski-rental bound checks use, and what an aborted
in-flight ping is booked at.
Sourcepub fn exposure_next_usd(&self) -> f64
pub fn exposure_next_usd(&self) -> f64
Most the next ping can bill once dispatched, a full cache miss
included (≥ worst_next_usd): what the
max_session_cost admission check uses.
pub fn prefix_tokens(&self) -> u64
pub fn next_at(&self) -> Instant
pub fn mode(&self) -> CacheKeepWarm
pub fn fired_age(&self) -> Duration
pub fn in_flight(&self) -> bool
Sourcepub fn set_mode(&mut self, mode: CacheKeepWarm)
pub fn set_mode(&mut self, mode: CacheKeepWarm)
/keepwarm auto|<N>h while a period runs: the new window applies.
Sourcepub fn deadline(&self, now: Instant, wall: SystemTime) -> Option<Instant>
pub fn deadline(&self, now: Instant, wall: SystemTime) -> Option<Instant>
When the next ping is due: the earlier of the monotonic deadline and
the wall-clock deadline mapped onto now (after a suspend the
monotonic one is late by the time slept). None while in flight.
Sourcepub fn fire(
&mut self,
now: Instant,
wall: SystemTime,
session_cost: f64,
max_session_cost: Option<f64>,
) -> Fire
pub fn fire( &mut self, now: Instant, wall: SystemTime, session_cost: f64, max_session_cost: Option<f64>, ) -> Fire
The timer fired. Ping marks the ping in flight.
Sourcepub fn charge(&mut self, cost_usd: f64)
pub fn charge(&mut self, cost_usd: f64)
Book spend that belongs to this period (every ping, failed or not).
Sourcepub fn ping_sent(
&mut self,
usage: &KeepWarmUsage,
anchor: Option<CacheAnchor>,
downgraded: bool,
) -> Result<(), PeriodEnd>
pub fn ping_sent( &mut self, usage: &KeepWarmUsage, anchor: Option<CacheAnchor>, downgraded: bool, ) -> Result<(), PeriodEnd>
The in-flight ping was sent and accepted (its cost already
charged); anchor is the runtime’s anchor after it,
downgraded the session’s silent-downgrade latch. Schedules the next
ping or says why the period is over.
Sourcepub fn ping_failed(
&mut self,
failure: &PingFailure,
now: Instant,
wall: SystemTime,
) -> Result<Duration, PeriodEnd>
pub fn ping_failed( &mut self, failure: &PingFailure, now: Instant, wall: SystemTime, ) -> Result<Duration, PeriodEnd>
The in-flight ping failed (its cost, if any, already charged). Transient failures retry with bounded backoff as long as the retry still lands before expiry.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Period
impl RefUnwindSafe for Period
impl Send for Period
impl Sync for Period
impl Unpin for Period
impl UnsafeUnpin for Period
impl UnwindSafe for Period
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.