pub trait DeadlineStore: Send + Sync {
// Required methods
async fn register(&self, deadline: &Deadline) -> Result<(), EngineError>;
async fn cancel(&self, id: DeadlineId) -> Result<(), EngineError>;
async fn due_now(&self, limit: usize) -> Result<DueNowResult, EngineError>;
async fn for_stream(
&self,
stream_id: &StreamId,
) -> Result<Vec<Deadline>, EngineError>;
async fn len(&self) -> Result<usize, EngineError>;
// Provided methods
async fn is_empty(&self) -> Result<bool, EngineError> { ... }
async fn overdue_count(&self) -> Result<usize, EngineError> { ... }
}Expand description
Storage contract for process deadlines.
§Scheduler contract
A background timer task should poll this store periodically:
- Call
DeadlineStore::due_nowto retrieve expired deadlines. - Dispatch a
TimeoutDeadlinecommand to each owning process. - Call
DeadlineStore::cancelto remove the fired deadline.
Cancelling a deadline before the scheduler fires it prevents a spurious
TimeoutDeadline command from being dispatched to the process. Always
cancel deadlines when the process advances past them naturally (e.g. when
the expected counterparty response arrives in time).
§Blanket Arc implementation
Arc<S> implements DeadlineStore whenever S: DeadlineStore, enabling
shared access from both the scheduler and command handlers.
Required Methods§
Sourceasync fn register(&self, deadline: &Deadline) -> Result<(), EngineError>
async fn register(&self, deadline: &Deadline) -> Result<(), EngineError>
Register a new deadline.
Upserts by deadline_id: if a deadline with the same ID already
exists it is replaced.
§Errors
Returns EngineError::Deadline on storage failure.
Sourceasync fn cancel(&self, id: DeadlineId) -> Result<(), EngineError>
async fn cancel(&self, id: DeadlineId) -> Result<(), EngineError>
Cancel a registered deadline by ID.
No-op when the deadline does not exist.
§Errors
Returns EngineError::Deadline on storage failure.
Sourceasync fn due_now(&self, limit: usize) -> Result<DueNowResult, EngineError>
async fn due_now(&self, limit: usize) -> Result<DueNowResult, EngineError>
Return up to limit deadlines whose due_at <= now_utc(), ordered
soonest-first.
When the store contains more expired deadlines than limit, the
returned DueNowResult::has_more is true. Callers should drain
in a loop until has_more is false.
§Errors
Returns EngineError::Deadline on storage failure.
Sourceasync fn for_stream(
&self,
stream_id: &StreamId,
) -> Result<Vec<Deadline>, EngineError>
async fn for_stream( &self, stream_id: &StreamId, ) -> Result<Vec<Deadline>, EngineError>
Return all active deadlines for stream_id, in registration order.
§Errors
Returns EngineError::Deadline on storage failure.
Sourceasync fn len(&self) -> Result<usize, EngineError>
async fn len(&self) -> Result<usize, EngineError>
Provided Methods§
Sourceasync fn is_empty(&self) -> Result<bool, EngineError>
async fn is_empty(&self) -> Result<bool, EngineError>
Return true when no deadlines are registered.
§Errors
Returns EngineError::Deadline on storage failure.
Sourceasync fn overdue_count(&self) -> Result<usize, EngineError>
async fn overdue_count(&self) -> Result<usize, EngineError>
Count deadlines whose due_at ≤ now that have not yet been cancelled.
Indicates scheduler lag: a non-zero value means TimeoutExpired commands
are not being dispatched in time, which is a compliance violation.
The default implementation delegates to due_now with a limit of
10 000; if there are more overdue deadlines, returns 10 000 (capped).
Implementations can override for a more efficient point-count query.
§Errors
Returns EngineError::Deadline on storage failure.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".