pub struct WorkflowBuilder<D: WorkflowData> {
pub steps: Vec<WorkflowStep>,
pub last_step: Option<usize>,
/* private fields */
}Expand description
Fluent builder for constructing workflow definitions.
Uses an owned-self pattern: each method consumes and returns the builder, avoiding lifetime issues with mutable borrows.
§Example
let def = WorkflowBuilder::<MyData>::new()
.start_with::<StepA>()
.name("Step A")
.then::<StepB>()
.name("Step B")
.end_workflow()
.build("my-workflow", 1);Fields§
§steps: Vec<WorkflowStep>Steps.
last_step: Option<usize>Last step.
Implementations§
Source§impl<D: WorkflowData> WorkflowBuilder<D>
impl<D: WorkflowData> WorkflowBuilder<D>
Sourcepub fn default_error_behavior(self, behavior: ErrorBehavior) -> Self
pub fn default_error_behavior(self, behavior: ErrorBehavior) -> Self
Set the default error behavior for all steps in this workflow.
Steps that don’t have their own on_error
configuration will use this behavior when they fail.
Sourcepub fn start_with<S: StepBody + Default + 'static>(self) -> StepBuilder<D>
pub fn start_with<S: StepBody + Default + 'static>(self) -> StepBuilder<D>
Add the first step of the workflow.
Returns a StepBuilder so you can configure the step’s name, error
behavior, and compensation before chaining the next step.
§Example
let def = WorkflowBuilder::<MyData>::new()
.start_with::<FetchData>()
.name("Fetch")
.then::<Process>()
.name("Process")
.end_workflow()
.build("my-workflow", 1);Sourcepub fn add_step(&mut self, step_type: &str) -> usize
pub fn add_step(&mut self, step_type: &str) -> usize
Add a step by type name. Used by container builder closures.
Sourcepub fn add_step_typed<S: StepBody + Default + 'static>(
&mut self,
name: &str,
config: Option<Value>,
) -> usize
pub fn add_step_typed<S: StepBody + Default + 'static>( &mut self, name: &str, config: Option<Value>, ) -> usize
Add a typed step with an optional name and config.
Convenience for use inside parallel branch closures.
Sourcepub fn wire_outcome(
&mut self,
from_step: usize,
to_step: usize,
value: Option<Value>,
)
pub fn wire_outcome( &mut self, from_step: usize, to_step: usize, value: Option<Value>, )
Wire an outcome from from_step to to_step.
Sourcepub fn build(self, id: impl Into<String>, version: u32) -> WorkflowDefinition
pub fn build(self, id: impl Into<String>, version: u32) -> WorkflowDefinition
Compile the builder into a WorkflowDefinition.
The id and version together uniquely identify this workflow blueprint.
Definitions are registered with a WorkflowHost
before instances can be started.
Note: inline closures added via StepBuilder::then_fn are discarded
by this method. Use build_with_closures if you
need to retain them for runtime registration.
Sourcepub fn build_with_closures(
self,
id: impl Into<String>,
version: u32,
) -> (WorkflowDefinition, HashMap<usize, Box<dyn Fn() -> ExecutionResult + Send + Sync>>)
pub fn build_with_closures( self, id: impl Into<String>, version: u32, ) -> (WorkflowDefinition, HashMap<usize, Box<dyn Fn() -> ExecutionResult + Send + Sync>>)
Compile the builder into a WorkflowDefinition and return any inline closures.
Inline closures (added with StepBuilder::then_fn) are keyed by step id
in the returned HashMap. You must register these closures with the
StepRegistry at runtime so the executor
can invoke them.
Sourcepub fn register_inline_steps(
self,
registry: &mut StepRegistry,
id: impl Into<String>,
version: u32,
) -> WorkflowDefinition
pub fn register_inline_steps( self, registry: &mut StepRegistry, id: impl Into<String>, version: u32, ) -> WorkflowDefinition
Register all inline closures from this builder into the given step registry.
Each inline closure is registered under a unique key derived from the
InlineStep type name and step id.