Skip to main content

WorkflowRunner

Struct WorkflowRunner 

Source
pub struct WorkflowRunner { /* private fields */ }
Expand description

The main workflow runner that executes workflow definitions

Implementations§

Source§

impl WorkflowRunner

Source

pub fn new(workflow: WorkflowDefinition) -> WorkflowResult<Self>

Creates a new WorkflowRunner for the given workflow definition

Source

pub fn with_secret_manager(self, manager: Arc<dyn SecretManager>) -> Self

Sets the secret manager for $secret expression variable

Source

pub fn with_listener(self, listener: Arc<dyn WorkflowExecutionListener>) -> Self

Sets the execution listener for workflow/task events

Source

pub fn with_event_bus(self, bus: SharedEventBus) -> Self

Sets the event bus for emit/listen tasks

Source

pub fn with_sub_workflow(self, workflow: WorkflowDefinition) -> Self

Registers a sub-workflow that can be invoked via run: workflow Keyed by “namespace/name/version”

Source

pub fn with_call_handler(self, handler: Box<dyn CallHandler>) -> Self

Registers a custom call handler for a specific call type (e.g., “grpc”, “openapi”, “asyncapi”, “a2a”)

Source

pub fn with_run_handler(self, handler: Box<dyn RunHandler>) -> Self

Registers a custom run handler for a specific run type (e.g., “container”, “script”)

Source

pub fn with_function(self, name: &str, task: TaskDefinition) -> Self

Registers a named function definition for call.function resolution

This allows registering external function definitions that can be referenced by call: <functionName> in workflows, similar to Java SDK’s cataloged function mechanism.

Source

pub fn with_handler_registry(self, registry: HandlerRegistry) -> Self

Sets the entire handler registry (used for propagating handlers to child runners)

Source

pub fn with_custom_task_handler( self, handler: Box<dyn CustomTaskHandler>, ) -> Self

Registers a custom task handler for a specific custom task type

Source

pub fn with_expression_engine(self, engine: Arc<dyn ExpressionEngine>) -> Self

Registers a custom expression engine for a specific prefix (e.g., “cel”, “js”)

Expressions prefixed with engine_prefix: will be routed to this engine. Unprefixed expressions default to JQ.

Source

pub fn with_expression_engine_registry( self, registry: ExpressionEngineRegistry, ) -> Self

Sets the expression engine registry (replaces all previously registered engines). Useful for propagating engines from a parent runner to a child runner.

Source

pub fn with_variable(self, name: impl Into<String>, value: Value) -> Self

Injects a custom variable into the JQ expression context.

The variable will be available as $name in all expressions (input.from, output.as, switch conditions, etc.). This is useful for passing external configuration or environment information into the workflow.

§Example
use swf_runtime::WorkflowRunner;
use serde_json::json;

let runner = WorkflowRunner::new(workflow)
    .expect("failed to create runner")
    .with_variable("config", json!({"base_url": "https://api.example.com"}))
    .with_variable("env", json!({"region": "us-east-1"}));
Source

pub async fn run(&self, input: Value) -> WorkflowResult<Value>

Runs the workflow with the given input and returns the output

Source

pub fn workflow(&self) -> &WorkflowDefinition

Returns a reference to the workflow definition

Source

pub fn handle(&self) -> WorkflowHandle

Returns a WorkflowHandle that can suspend/resume the running workflow

Must be called before run(). The handle shares suspend/resume state with the workflow context via Arc.

Source

pub fn schedule(self, input: Value) -> ScheduledWorkflow

Runs the workflow on a recurring schedule based on the workflow’s schedule.every or schedule.cron definition.

For every: runs the workflow at fixed intervals. For cron: runs the workflow according to the cron expression schedule.

Returns a ScheduledWorkflow that can be cancelled to stop the schedule. If no schedule is defined, runs once and returns a completed handle.

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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