Skip to main content

WorkflowBuilder

Struct WorkflowBuilder 

Source
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>

Source

pub fn new() -> Self

New.

Source

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.

Source

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);
Source

pub fn add_step(&mut self, step_type: &str) -> usize

Add a step by type name. Used by container builder closures.

Source

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.

Source

pub fn wire_outcome( &mut self, from_step: usize, to_step: usize, value: Option<Value>, )

Wire an outcome from from_step to to_step.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<D: WorkflowData> Default for WorkflowBuilder<D>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<D> Freeze for WorkflowBuilder<D>

§

impl<D> !RefUnwindSafe for WorkflowBuilder<D>

§

impl<D> Send for WorkflowBuilder<D>

§

impl<D> Sync for WorkflowBuilder<D>

§

impl<D> Unpin for WorkflowBuilder<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for WorkflowBuilder<D>

§

impl<D> !UnwindSafe for WorkflowBuilder<D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more