Skip to main content

TimerService

Struct TimerService 

Source
pub struct TimerService { /* private fields */ }
Expand description

Durable timer scheduling and wheel-fire handling.

The service owns the AT live path for timers. Workflow-issued TimerStarted events are recorded by AD’s resume-live handoff before this service is called; this service persists only the durable timer row and later asynchronous arrival/cancellation history through the engine recorder seam.

Implementations§

Source§

impl TimerService

Source

pub fn new( engine: Arc<dyn EngineHandle>, store: Arc<dyn ReadableEventStore>, ) -> Self

Creates a durable timer service from the engine seam and timer store.

Source

pub fn with_recorded_at( engine: Arc<dyn EngineHandle>, store: Arc<dyn ReadableEventStore>, recorded_at: fn() -> DateTime<Utc>, ) -> Self

Creates a durable timer service with an injected history timestamp source.

Source

pub fn with_terminal_updates( self, terminal_updates: Arc<DashSet<(WorkflowId, TimerId)>>, ) -> Self

Replaces this service’s per-timer terminal-update coordinator with a shared one, returning the service for chaining.

The production timer bridge owns ONE coordinator and hands it to every TimerService it constructs, so a cancel obtained from one service and a fire obtained from another still serialize per timer (first-recorded wins). Without this, each service would guard against itself only.

Source

pub fn with_deadline_handler(self, handler: Arc<dyn DeadlineHandler>) -> Self

Registers the engine-side deadline handler for reserved deadline:{run_id} fires, returning the service for chaining.

The production timer bridge calls this so both the live wheel and recover_due (which share Self::fire_timer) demux a deadline fire to the handler instead of recording a generic TimerFired.

Source

pub async fn schedule( &self, workflow_id: WorkflowId, timer_id: TimerId, fire_at: DateTime<Utc>, ) -> Result<(), TimerServiceError>

Schedules a durable timer and arms the live wheel when the workflow is resident.

The operation persists the durable timer row and arms the wheel when needed. The command-issued TimerStarted recorder event is appended by AD’s resume-live handoff before AE/AT reaches this service, so this method deliberately does not record it again.

§Errors

Returns TimerServiceError when durable storage, recording, residency resolution, or wheel arming fails.

Source

pub async fn cancel( &self, workflow_id: WorkflowId, timer_id: TimerId, cause: TimerCancelCause, ) -> Result<(), TimerServiceError>

Cancels a durable timer that has not already reached a terminal timer state.

Already-fired and already-cancelled timers are treated as idempotent no-ops. For active resident timers the live wheel is disarmed through the engine seam before TimerCancelled is recorded through the workflow recorder seam. Non-resident timers still record the cancellation so recovery/replay can suppress a later fire.

Anonymous timers are accepted: authors can never address one (the SDK’s cancel_timer takes a TimerRef minted by start_timer, which is always named), but the engine settles with_timeout scope deadlines — anonymous by construction — through this first-recorded-wins race against Self::fire_timer.

§Errors

Returns TimerServiceError when history inspection, residency resolution, wheel disarming, or event recording fails.

Source

pub async fn fire_timer( &self, workflow_id: WorkflowId, timer_id: TimerId, fire_at: DateTime<Utc>, ) -> Result<(), TimerServiceError>

Handles a live timer-wheel fire.

TimerFired is recorded before any mailbox delivery. If the workflow is no longer resident, the recorded event remains the durable observation that replay/recovery can surface later.

§Errors

Returns TimerServiceError when history inspection, recording, residency resolution, or live mailbox delivery fails.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more