Skip to main content

EffectStore

Trait EffectStore 

Source
pub trait EffectStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn insert_or_get(
        &self,
        new: NewEffect,
    ) -> impl Future<Output = Result<InsertOutcome, StoreError>> + Send;
    fn get(
        &self,
        id: EffectId,
    ) -> impl Future<Output = Result<Option<EffectRecord>, StoreError>> + Send;
    fn get_by_key(
        &self,
        key: &EffectKey,
    ) -> impl Future<Output = Result<Option<EffectRecord>, StoreError>> + Send;
    fn acquire_lease(
        &self,
        id: EffectId,
        owner: &WorkerId,
        now: SystemTime,
        ttl: Duration,
    ) -> impl Future<Output = Result<Lease, StoreError>> + Send;
    fn renew_lease(
        &self,
        lease: &Lease,
        now: SystemTime,
        ttl: Duration,
    ) -> impl Future<Output = Result<Lease, StoreError>> + Send;
    fn release_lease(
        &self,
        lease: &Lease,
    ) -> impl Future<Output = Result<(), StoreError>> + Send;
    fn transition(
        &self,
        request: TransitionRequest,
    ) -> impl Future<Output = Result<EffectRecord, StoreError>> + Send;
    fn list(
        &self,
        query: ListQuery,
    ) -> impl Future<Output = Result<Vec<EffectRecord>, StoreError>> + Send;
    fn events(
        &self,
        id: EffectId,
    ) -> impl Future<Output = Result<Vec<EffectEvent>, StoreError>> + Send;
    fn prune(
        &self,
        query: PruneQuery,
    ) -> impl Future<Output = Result<u64, StoreError>> + Send;
}
Expand description

Persistence for effect records, leases and audit events.

Times are passed in by the caller rather than read from a clock, so the runtime’s clock governs leases. Stores must keep at least millisecond precision.

Every method that changes a record must apply the change through the matching EffectRecord method inside one atomic unit (a transaction or a lock), so concurrent callers can never interleave between the check and the write.

Required Methods§

Source

fn insert_or_get( &self, new: NewEffect, ) -> impl Future<Output = Result<InsertOutcome, StoreError>> + Send

Inserts a new effect, or returns the existing record with the same EffectKey untouched.

Atomic on the key: of any number of concurrent calls for one key, exactly one reports InsertOutcome::inserted.

Source

fn get( &self, id: EffectId, ) -> impl Future<Output = Result<Option<EffectRecord>, StoreError>> + Send

Loads a record by id.

Source

fn get_by_key( &self, key: &EffectKey, ) -> impl Future<Output = Result<Option<EffectRecord>, StoreError>> + Send

Loads a record by its logical identity.

Source

fn acquire_lease( &self, id: EffectId, owner: &WorkerId, now: SystemTime, ttl: Duration, ) -> impl Future<Output = Result<Lease, StoreError>> + Send

Takes the execution lease, via EffectRecord::acquire_lease.

Source

fn renew_lease( &self, lease: &Lease, now: SystemTime, ttl: Duration, ) -> impl Future<Output = Result<Lease, StoreError>> + Send

Extends a held lease, via EffectRecord::renew_lease.

Source

fn release_lease( &self, lease: &Lease, ) -> impl Future<Output = Result<(), StoreError>> + Send

Gives up a lease, via EffectRecord::release_lease. Releasing a lease that was already lost is not an error.

Source

fn transition( &self, request: TransitionRequest, ) -> impl Future<Output = Result<EffectRecord, StoreError>> + Send

Applies a status transition, via EffectRecord::apply, and appends its audit event in the same atomic unit. Returns the updated record.

Source

fn list( &self, query: ListQuery, ) -> impl Future<Output = Result<Vec<EffectRecord>, StoreError>> + Send

Lists records matching query, ordered by id (creation time).

Source

fn events( &self, id: EffectId, ) -> impl Future<Output = Result<Vec<EffectEvent>, StoreError>> + Send

The audit events of one effect, ordered by sequence.

Source

fn prune( &self, query: PruneQuery, ) -> impl Future<Output = Result<u64, StoreError>> + Send

Deletes up to query.limit records matching query, lowest id first, together with their audit events, and returns how many it deleted. Each record is checked and deleted atomically, so a record that a worker leases or changes concurrently is either deleted before that change or not at all.

A deleted key is free: the next insert_or_get for it inserts a new record. A query for a status that is not settled deletes nothing.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§