Skip to main content

WorkState

Trait WorkState 

Source
pub trait WorkState: Send + Sync {
    // Required methods
    fn claim_strength(&self) -> ClaimStrength;
    fn pull_ready<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<WorkTicket>, SourceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn active_claims<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ActiveClaim>, SourceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn claim<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ticket: &'life1 TicketRef,
        owner: &'life2 OwnerId,
        ttl: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<ClaimResult, SourceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn renew<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ticket: &'life1 TicketRef,
        owner: &'life2 OwnerId,
    ) -> Pin<Box<dyn Future<Output = Result<ClaimResult, SourceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn release<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ticket: &'life1 TicketRef,
        owner: &'life2 OwnerId,
        disposition: Disposition,
    ) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn push_outcome<'life0, 'life1, 'async_trait>(
        &'life0 self,
        outcome: &'life1 WorkOutcome,
    ) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

The daemon-facing contract for reading and claiming work.

Implementations must uphold these invariants:

Required Methods§

Source

fn claim_strength(&self) -> ClaimStrength

What this source can promise about claims. The dispatcher never branches on this; it exists for status display and for refusing multi-writer setups on LocalOnly sources.

Source

fn pull_ready<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<WorkTicket>, SourceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Refresh the daemon’s read cache. Selection runs on the cache; pull is periodic, never per-tick.

Source

fn active_claims<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ActiveClaim>, SourceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Claims visible at the source. Recovery compares these with recorded runs and releases a claim whose second admission commit never landed.

Source

fn claim<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ticket: &'life1 TicketRef, owner: &'life2 OwnerId, ttl: Duration, ) -> Pin<Box<dyn Future<Output = Result<ClaimResult, SourceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The only authoritative check. Succeeds iff the ticket is still ready at the source. Lost is a normal, silent outcome.

Source

fn renew<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ticket: &'life1 TicketRef, owner: &'life2 OwnerId, ) -> Pin<Box<dyn Future<Output = Result<ClaimResult, SourceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Heartbeat for long runs. An expired claim is reclaimable by peers.

Source

fn release<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ticket: &'life1 TicketRef, owner: &'life2 OwnerId, disposition: Disposition, ) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Give the ticket back, per policy. Repeating a completed release is an idempotent success; it never consumes another attempt.

Source

fn push_outcome<'life0, 'life1, 'async_trait>( &'life0 self, outcome: &'life1 WorkOutcome, ) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Terminal push. Fire-and-forget from the dispatcher’s view.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl WorkState for LocalSqlite

SQLite satisfies atomic claims with an IMMEDIATE transaction and a conditional ticket update. The ticket row is authoritative for attempts: claim consumes one attempt, while release preserves that count as evidence of the completed try. This backend never records runs, and its local-source outcome push is idempotent because release already applied the durable ticket state.