sayiir_runtime/runner/mod.rs
1//! Module for workflow runners.
2//!
3//! A workflow runner is responsible for executing workflows.
4//! Different implementations can provide different execution strategies,
5//! such as in-process execution, distributed execution, or execution with
6//! persistence and recovery.
7
8use sayiir_core::codec::Codec;
9use sayiir_core::codec::sealed;
10use sayiir_core::workflow::{Workflow, WorkflowStatus};
11use std::future::Future;
12
13use crate::error::RuntimeError;
14
15/// A trait for executing workflows.
16///
17/// Different implementations can provide different execution strategies,
18/// such as in-process execution, distributed execution, or execution with
19/// persistence and recovery.
20///
21/// Note: This trait uses `impl Future` which makes it non-object-safe.
22/// If you need dynamic dispatch, wrap implementations in an enum.
23pub trait WorkflowRunner: Send + Sync {
24 /// Run a workflow with the given input.
25 ///
26 /// The input type must match the input type of the first task added via `then`.
27 /// Returns the workflow execution status.
28 fn run<'w, C, Input, M>(
29 &self,
30 workflow: &'w Workflow<C, Input, M>,
31 input: Input,
32 ) -> impl Future<Output = Result<WorkflowStatus, RuntimeError>> + Send + 'w
33 where
34 Input: Send + 'static,
35 M: Send + Sync + 'static,
36 C: Codec + sealed::EncodeValue<Input>;
37}
38
39pub mod distributed;
40pub mod in_process;