Skip to main content

DeadlineStore

Trait DeadlineStore 

Source
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:

  1. Call DeadlineStore::due_now to retrieve expired deadlines.
  2. Dispatch a TimeoutDeadline command to each owning process.
  3. Call DeadlineStore::cancel to 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§

Source

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.

Source

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.

Source

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.

Source

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.

Source

async fn len(&self) -> Result<usize, EngineError>

Total number of registered deadlines.

§Errors

Returns EngineError::Deadline on storage failure.

Provided Methods§

Source

async fn is_empty(&self) -> Result<bool, EngineError>

Return true when no deadlines are registered.

§Errors

Returns EngineError::Deadline on storage failure.

Source

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".

Implementations on Foreign Types§

Source§

impl<S: DeadlineStore> DeadlineStore for Arc<S>

Source§

async fn register(&self, deadline: &Deadline) -> Result<(), EngineError>

Source§

async fn cancel(&self, id: DeadlineId) -> Result<(), EngineError>

Source§

async fn due_now(&self, limit: usize) -> Result<DueNowResult, EngineError>

Source§

async fn for_stream( &self, stream_id: &StreamId, ) -> Result<Vec<Deadline>, EngineError>

Source§

async fn len(&self) -> Result<usize, EngineError>

Source§

async fn overdue_count(&self) -> Result<usize, EngineError>

Implementors§