pub struct DurableTimerService { /* private fields */ }Expand description
Background task that fires durable timers whose instant has arrived.
Spawn DurableTimerService::run on a supervised task. It owns no timer state of its own — the
durable_timers table is the source of truth — so it is safe to stop and restart: a restarted
service re-reads due timers and fires any that elapsed while it was down.
Implementations§
Source§impl DurableTimerService
impl DurableTimerService
Sourcepub fn new(backend: Arc<DurableBackendEnum>, poll_interval: Duration) -> Self
pub fn new(backend: Arc<DurableBackendEnum>, poll_interval: Duration) -> Self
Build the service from the shared backend and a poll cadence.
poll_interval is the worst-case latency between a timer’s instant and its firing; the
promise_poll_interval_secs config value (default 2 s) is the natural source.
§Examples
use std::sync::Arc;
use std::time::Duration;
use zeph_durable::{DurableBackendEnum, DurableTimerService, LocalBackend};
let backend = Arc::new(DurableBackendEnum::Local(Arc::new(
LocalBackend::open("durable.db", 1_048_576).await?,
)));
let service = DurableTimerService::new(backend, Duration::from_secs(2));
let task = tokio::spawn(service.run());Sourcepub async fn run(self)
pub async fn run(self)
Run the timer poll loop until the task is aborted.
Each tick fires every timer whose due_at has elapsed (including, on the first tick after a
restart, timers that came due during downtime — FR-DE-06). A backend error is logged and the
loop continues so a transient failure does not strand future timers.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DurableTimerService
impl !UnwindSafe for DurableTimerService
impl Freeze for DurableTimerService
impl Send for DurableTimerService
impl Sync for DurableTimerService
impl Unpin for DurableTimerService
impl UnsafeUnpin for DurableTimerService
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