laravel-rust-workflow 0.2.0

Internal crate of Laravel for Rust: durable workflows. Depend on `laravel-rust` instead
Documentation
use std::collections::BTreeMap;
use std::sync::Arc;
use std::time::Duration;

use futures_util::future::BoxFuture;
use jiff::Timestamp;

use super::{Claim, Created, Delivery, Entry, Filter, Lease, NewRun, Outcome, RunRecord, Waited};
use crate::Result;
use crate::container::LazyDriver;
use crate::workflow::ErasedStore;
use crate::workflow::{RunId, StoreDefinition};

pub(crate) type LazyStore = LazyDriver<StoreDefinition, Arc<dyn ErasedStore>>;

impl ErasedStore for LazyStore {
    fn create(&self, run: NewRun) -> BoxFuture<'_, Result<Created>> {
        Box::pin(async move { self.get().await?.create(run).await })
    }

    fn claim(&self, id: RunId, lease: Duration) -> BoxFuture<'_, Result<Claim>> {
        Box::pin(async move { self.get().await?.claim(id, lease).await })
    }

    fn record<'a>(&'a self, id: RunId, lease: &'a Lease, entry: Entry) -> BoxFuture<'a, Result<bool>> {
        Box::pin(async move { self.get().await?.record(id, lease, entry).await })
    }

    fn wait<'a>(&'a self, id: RunId, lease: &'a Lease, token: &'a str, number: u32) -> BoxFuture<'a, Result<Waited>> {
        Box::pin(async move { self.get().await?.wait(id, lease, token, number).await })
    }

    fn stop_waiting<'a>(&'a self, id: RunId, lease: &'a Lease, token: &'a str) -> BoxFuture<'a, Result<bool>> {
        Box::pin(async move { self.get().await?.stop_waiting(id, lease, token).await })
    }

    fn resume<'a>(&'a self, token: &'a str, value: String) -> BoxFuture<'a, Result<Delivery>> {
        Box::pin(async move { self.get().await?.resume(token, value).await })
    }

    fn waiting<'a>(&'a self, token: &'a str) -> BoxFuture<'a, Result<Option<RunId>>> {
        Box::pin(async move { self.get().await?.waiting(token).await })
    }

    fn set_attributes<'a>(
        &'a self,
        id: RunId,
        lease: &'a Lease,
        attributes: BTreeMap<String, String>,
    ) -> BoxFuture<'a, Result<bool>> {
        Box::pin(async move { self.get().await?.set_attributes(id, lease, attributes).await })
    }

    fn renew<'a>(&'a self, id: RunId, lease: &'a Lease, duration: Duration) -> BoxFuture<'a, Result<bool>> {
        Box::pin(async move { self.get().await?.renew(id, lease, duration).await })
    }

    fn release<'a>(
        &'a self,
        id: RunId,
        lease: &'a Lease,
        outcome: Outcome,
        now: Timestamp,
    ) -> BoxFuture<'a, Result<bool>> {
        Box::pin(async move { self.get().await?.release(id, lease, outcome, now).await })
    }

    fn find(&self, id: RunId) -> BoxFuture<'_, Result<Option<RunRecord>>> {
        Box::pin(async move { self.get().await?.find(id).await })
    }

    fn entries(&self, id: RunId) -> BoxFuture<'_, Result<Vec<Entry>>> {
        Box::pin(async move { self.get().await?.entries(id).await })
    }

    fn list(&self, filter: Filter) -> BoxFuture<'_, Result<Vec<RunRecord>>> {
        Box::pin(async move { self.get().await?.list(filter).await })
    }

    fn cancel(&self, id: RunId, reason: Option<String>, now: Timestamp) -> BoxFuture<'_, Result<bool>> {
        Box::pin(async move { self.get().await?.cancel(id, reason, now).await })
    }

    fn retry(&self, id: RunId, now: Timestamp) -> BoxFuture<'_, Result<bool>> {
        Box::pin(async move { self.get().await?.retry(id, now).await })
    }

    fn overdue(&self, now: Timestamp) -> BoxFuture<'_, Result<Vec<RunRecord>>> {
        Box::pin(async move { self.get().await?.overdue(now).await })
    }

    fn prune(&self, before: Timestamp) -> BoxFuture<'_, Result<u64>> {
        Box::pin(async move { self.get().await?.prune(before).await })
    }
}