feat(wfe-core): add fluent workflow builder API
Owned-self builder pattern (no lifetime parameters). WorkflowBuilder chains start_with/then/end_workflow to produce WorkflowDefinition. StepBuilder supports: name, id, on_error, compensate_with, then, then_fn, wait_for, delay, if_do, while_do, for_each, saga, parallel. ParallelBuilder for branching with join semantics. InlineStep for closure-based steps. Step config stored on WorkflowStep.step_config.
This commit is contained in:
30
wfe-core/src/builder/inline_step.rs
Normal file
30
wfe-core/src/builder/inline_step.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::models::ExecutionResult;
|
||||
use crate::traits::step::{StepBody, StepExecutionContext};
|
||||
|
||||
type InlineFn = Box<dyn Fn() -> ExecutionResult + Send + Sync>;
|
||||
|
||||
/// A step that wraps an inline closure.
|
||||
pub struct InlineStep {
|
||||
body: InlineFn,
|
||||
}
|
||||
|
||||
impl InlineStep {
|
||||
pub fn new(f: impl Fn() -> ExecutionResult + Send + Sync + 'static) -> Self {
|
||||
Self { body: Box::new(f) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InlineStep {
|
||||
fn default() -> Self {
|
||||
Self::new(ExecutionResult::next)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl StepBody for InlineStep {
|
||||
async fn run(&mut self, _context: &StepExecutionContext<'_>) -> crate::Result<ExecutionResult> {
|
||||
Ok((self.body)())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user