Skip to main content

FlowRunner

Struct FlowRunner 

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

Executes a DagGraph using registered Node implementations.

For lifecycle control (pause / resume / terminate), use FlowEngine instead of constructing a FlowRunner directly.

§Example

use a3s_flow::{DagGraph, FlowRunner, NodeRegistry};
use serde_json::json;

#[tokio::main]
async fn main() {
    let def = json!({
        "nodes": [
            { "id": "start", "type": "noop" },
            { "id": "end",   "type": "noop" }
        ],
        "edges": [{ "source": "start", "target": "end" }]
    });
    let dag = DagGraph::from_json(&def).unwrap();
    let registry = NodeRegistry::with_defaults();
    let runner = FlowRunner::new(dag, registry);
    let result = runner.run(Default::default()).await.unwrap();
    println!("{:?}", result.outputs);
}

Implementations§

Source§

impl FlowRunner

Source

pub fn new(dag: DagGraph, registry: NodeRegistry) -> Self

Create a new runner from a validated DAG and a node registry.

Uses NoopEventEmitter by default. Call .with_event_emitter to register a custom listener before executing.

Source

pub fn with_arc_registry(dag: DagGraph, registry: Arc<NodeRegistry>) -> Self

Create a new runner sharing an existing Arc<NodeRegistry>.

Used by the "iteration" and "sub-flow" nodes so that sub-flow runners share the same registry without extra Arc wrapping.

Source

pub fn with_event_emitter(self, emitter: Arc<dyn EventEmitter>) -> Self

Attach a custom event emitter to this runner.

The emitter receives node and flow lifecycle events during execution. Returns self for method chaining.

Source

pub fn with_flow_store(self, store: Arc<dyn FlowStore>) -> Self

Attach a flow definition store to this runner.

When set, the store is passed to every ExecContext so that nodes like "sub-flow" can load named flow definitions at execution time. Returns self for method chaining.

Source

pub fn with_max_concurrency(self, n: usize) -> Self

Limit the number of nodes that may execute concurrently within a single wave.

By default all ready nodes in a wave run in parallel. Setting max_concurrency to n caps this using a Tokio Semaphore so that at most n nodes are active at the same time. Useful when downstream services impose rate limits.

Returns self for method chaining.

Source

pub async fn run(&self, variables: HashMap<String, Value>) -> Result<FlowResult>

Execute the flow to completion with no external control signals.

Source

pub async fn resume_from( &self, prior: &FlowResult, variables: HashMap<String, Value>, ) -> Result<FlowResult>

Resume a flow from a prior (partial or complete) result, skipping nodes that already have outputs in prior.

A new execution ID is assigned to the resumed run. Nodes listed in prior.completed_nodes are not re-executed; their outputs from prior are used directly as inputs for any downstream nodes that still need to run.

§Example
let def = json!({ "nodes": [{ "id": "a", "type": "noop" }], "edges": [] });
let dag = DagGraph::from_json(&def).unwrap();
let runner = FlowRunner::new(dag, NodeRegistry::with_defaults());
let partial = runner.run(HashMap::new()).await.unwrap();
// Resume with the partial result — completed nodes are skipped.
let full = runner.resume_from(&partial, HashMap::new()).await.unwrap();

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