engine

package
v0.47.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package engine is orchestration only. Given one flow, it schedules nodes in dependency order, runs each node's declared assertion/output post-step, and recurses for sub-flows. It has no per-node-type logic: every kind is dispatched the same way. It records each node's outcome in a result.FlowResult and keeps going past a failure (skipping dependents) rather than aborting. The engine also satisfies node.SubflowRunner, so composite nodes recurse back into it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine runs flows.

func New

func New(deps node.Runtime, resolve func(string) (flow.Flow, bool), opts ...Option) *Engine

New builds an engine. resolve looks up child flows by id (pass nil when the flow has no sub-flows). The engine wires itself in as the sub-flow runner.

func (*Engine) RunFlow

func (e *Engine) RunFlow(ctx context.Context, f flow.Flow, inputs value.Map) *result.FlowResult

RunFlow executes a flow and returns its full result. Node failures are recorded in the result (Success=false), not returned as an error.

func (*Engine) RunInline

func (e *Engine) RunInline(ctx context.Context, f flow.Flow, in value.Map) (value.Map, error)

RunInline satisfies node.SubflowRunner for embedded body flows (loop, poll).

func (*Engine) RunSubflow

func (e *Engine) RunSubflow(ctx context.Context, flowID string, in value.Map) (value.Map, error)

RunSubflow satisfies node.SubflowRunner: it resolves a child flow by id and runs it, guarding against module cycles via the call stack carried in ctx.

type Event

type Event struct {
	Type   spi.EventType
	NodeID string
	Node   *result.NodeResult
	Flow   *result.FlowResult
}

Event is an execution event emitted during a top-level flow run. Node carries the node's result for node.* events; Flow carries the flow result for flow.* events.

A node that runs a sub-flow (module/loop/poll body) emits as one node event — its inner nodes are silent. This keeps the wire flat and re-running bodies (poll/loop) from storming events. If nested progress is ever needed, add depth to Event rather than un-silencing the recursion.

type Middleware

type Middleware func(NodeExec) NodeExec

Middleware wraps a NodeExec. The engine chains them outermost-first around every node.

func Retry

func Retry(attempts int) Middleware

Retry re-runs a node up to attempts times while it errors (including on an assertion failure), pausing a short ctx-respecting backoff between attempts. attempts <= 1 disables retry.

func Timeout

func Timeout(d time.Duration) Middleware

Timeout bounds each node's execution with a per-node deadline.

type NodeExec

type NodeExec func(ctx context.Context) (node.Result, assert.Results, error)

NodeExec is a node's run-and-assert unit — the innermost thing middleware wraps. Wrapping this (rather than just Execute) means retry re-runs the assertion pass too, matching the old runner's semantics.

type Observer

type Observer func(Event)

Observer receives execution events (progress streaming). It must be safe to call synchronously from the engine.

type Option

type Option func(*Engine)

Option configures an Engine at construction.

func WithMiddleware

func WithMiddleware(mw ...Middleware) Option

WithMiddleware wraps every node's run-and-assert unit (e.g. Retry, Timeout).

func WithObserver

func WithObserver(o Observer) Option

WithObserver attaches an execution-event observer (top-level flow only).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL