Skip to main content

wfe_core/traits/
step.rs

1use async_trait::async_trait;
2use serde::de::DeserializeOwned;
3use serde::Serialize;
4
5use crate::models::{ExecutionPointer, ExecutionResult, WorkflowInstance, WorkflowStep};
6
7/// Marker trait for all data types that flow between workflow steps.
8/// Anything that is serializable and deserializable qualifies.
9pub trait WorkflowData: Serialize + DeserializeOwned + Send + Sync + Clone + 'static {}
10
11/// Blanket implementation: any type satisfying the bounds is WorkflowData.
12impl<T> WorkflowData for T where T: Serialize + DeserializeOwned + Send + Sync + Clone + 'static {}
13
14/// Context available to a step during execution.
15#[derive(Debug)]
16pub struct StepExecutionContext<'a> {
17    /// The current item when iterating (ForEach).
18    pub item: Option<&'a serde_json::Value>,
19    /// The current execution pointer.
20    pub execution_pointer: &'a ExecutionPointer,
21    /// Persistence data from a previous execution of this step.
22    pub persistence_data: Option<&'a serde_json::Value>,
23    /// The step definition.
24    pub step: &'a WorkflowStep,
25    /// The running workflow instance.
26    pub workflow: &'a WorkflowInstance,
27    /// Cancellation token.
28    pub cancellation_token: tokio_util::sync::CancellationToken,
29}
30
31/// The core unit of work in a workflow. Each step implements this trait.
32#[async_trait]
33pub trait StepBody: Send + Sync {
34    async fn run(&mut self, context: &StepExecutionContext<'_>) -> crate::Result<ExecutionResult>;
35}