pub struct DeadlineScheduler<DS: DeadlineStore> { /* private fields */ }Expand description
A background task that polls DeadlineStore::due_now and dispatches
deadline commands to the owning processes via a caller-supplied function.
Obtain via EngineContext::run_deadline_scheduler and drive by spawning
DeadlineScheduler::run in a Tokio task.
§Dispatch function
The dispatch function receives a fired Deadline and returns a future
that dispatches the appropriate timeout command to the process. The function
is responsible for resuming the correct workflow and calling execute.
After the future completes, the scheduler cancels the deadline from the
store regardless of the dispatch outcome (to prevent re-firing).
use std::time::Duration;
let scheduler = ctx.run_deadline_scheduler(
|deadline| async move {
tracing::warn!(
deadline_id = %deadline.deadline_id(),
label = %deadline.label(),
"deadline fired",
);
Ok(())
},
100,
Duration::from_secs(30),
);
tokio::spawn(async move { scheduler.run().await });Implementations§
Source§impl<DS: DeadlineStore> DeadlineScheduler<DS>
impl<DS: DeadlineStore> DeadlineScheduler<DS>
Source§impl<DS: DeadlineStore> DeadlineScheduler<DS>
impl<DS: DeadlineStore> DeadlineScheduler<DS>
Sourcepub fn with_heartbeat(self, heartbeat: Arc<AtomicI64>) -> Self
pub fn with_heartbeat(self, heartbeat: Arc<AtomicI64>) -> Self
Attach a liveness heartbeat to this scheduler.
The scheduler will store the current UTC Unix timestamp (seconds) into
heartbeat at the end of every poll cycle.