feat(wfe-core): add models, traits, and error types

Core domain models: WorkflowInstance, ExecutionPointer, WorkflowDefinition,
WorkflowStep, Event, EventSubscription, ScheduledCommand, ExecutionError,
LifecycleEvent, PollEndpointConfig. All serde-serializable.

Provider traits: PersistenceProvider (composite of WorkflowRepository,
EventRepository, SubscriptionRepository, ScheduledCommandRepository),
DistributedLockProvider, QueueProvider, SearchIndex, LifecyclePublisher,
WorkflowMiddleware, StepMiddleware, WorkflowRegistry.

StepBody trait with StepExecutionContext for workflow step implementations.
WorkflowData marker trait (blanket impl for Serialize + DeserializeOwned).
This commit is contained in:
2026-03-25 20:07:50 +00:00
parent 098564db51
commit d87d888787
25 changed files with 1627 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
use async_trait::async_trait;
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::models::{ExecutionPointer, ExecutionResult, WorkflowInstance, WorkflowStep};
/// Marker trait for all data types that flow between workflow steps.
/// Anything that is serializable and deserializable qualifies.
pub trait WorkflowData: Serialize + DeserializeOwned + Send + Sync + Clone + 'static {}
/// Blanket implementation: any type satisfying the bounds is WorkflowData.
impl<T> WorkflowData for T where T: Serialize + DeserializeOwned + Send + Sync + Clone + 'static {}
/// Context available to a step during execution.
#[derive(Debug)]
pub struct StepExecutionContext<'a> {
/// The current item when iterating (ForEach).
pub item: Option<&'a serde_json::Value>,
/// The current execution pointer.
pub execution_pointer: &'a ExecutionPointer,
/// Persistence data from a previous execution of this step.
pub persistence_data: Option<&'a serde_json::Value>,
/// The step definition.
pub step: &'a WorkflowStep,
/// The running workflow instance.
pub workflow: &'a WorkflowInstance,
/// Cancellation token.
pub cancellation_token: tokio_util::sync::CancellationToken,
}
/// The core unit of work in a workflow. Each step implements this trait.
#[async_trait]
pub trait StepBody: Send + Sync {
async fn run(&mut self, context: &StepExecutionContext<'_>) -> crate::Result<ExecutionResult>;
}