pub struct StepRunner<'a, T>{ /* private fields */ }Expand description
A fluent builder for executing workflow steps.
Created via WorkflowContext::step().
Implementations§
Source§impl<'a, T> StepRunner<'a, T>
impl<'a, T> StepRunner<'a, T>
Sourcepub fn compensate<F, Fut>(self, f: F) -> Self
pub fn compensate<F, Fut>(self, f: F) -> Self
Set a compensation function (rollback handler).
If a later step fails, this compensation function will be called with the step’s result to undo its effects (saga pattern).
ⓘ
ctx.step("charge_card", || async { charge(&card).await })
.compensate(|charge_result| async move {
refund(&charge_result.charge_id).await
})
.run()
.await?;Sourcepub fn timeout(self, duration: Duration) -> Self
pub fn timeout(self, duration: Duration) -> Self
Set a timeout for this step.
ⓘ
ctx.step("slow_operation", || async { slow_op().await })
.timeout(Duration::from_secs(30))
.run()
.await?;Sourcepub fn optional(self) -> Self
pub fn optional(self) -> Self
Mark step as optional.
If an optional step fails, the workflow continues without triggering compensation of previous steps.
ⓘ
ctx.step("send_notification", || async { notify_slack().await })
.optional()
.run()
.await?; // Won't fail workflow if notification failsSourcepub async fn run(self) -> Result<T>
pub async fn run(self) -> Result<T>
Execute the step.
This runs the step with configured timeout and compensation settings. Returns the step result or an error.
Note: For retry support with the fluent API, consider using a retryable wrapper inside your step function, or use the low-level API with manual retry logic.
Auto Trait Implementations§
impl<'a, T> Freeze for StepRunner<'a, T>
impl<'a, T> !RefUnwindSafe for StepRunner<'a, T>
impl<'a, T> Send for StepRunner<'a, T>
impl<'a, T> !Sync for StepRunner<'a, T>
impl<'a, T> Unpin for StepRunner<'a, T>
impl<'a, T> !UnwindSafe for StepRunner<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more