flowexec

package
v0.0.0-...-e968d04 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package flowexec manages flow execution sessions. It orchestrates the flow lifecycle: variable resolution, node construction, runner creation, and result processing.

The ExecutionSession interface supports both local execution (ServerSession) and future distributed execution across regions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIProviderSnapshot

type AIProviderSnapshot struct{ Service *sflow.NodeAiProviderService }

func (*AIProviderSnapshot) Kind

func (s *AIProviderSnapshot) Kind() mflow.NodeKind

func (*AIProviderSnapshot) Read

func (s *AIProviderSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*AIProviderSnapshot) WriteTx

func (s *AIProviderSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type AISnapshot

type AISnapshot struct{ Service *sflow.NodeAIService }

func (*AISnapshot) Kind

func (s *AISnapshot) Kind() mflow.NodeKind

func (*AISnapshot) Read

func (s *AISnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*AISnapshot) WriteTx

func (s *AISnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type ConditionSnapshot

type ConditionSnapshot struct{ Service *sflow.NodeIfService }

func (*ConditionSnapshot) Kind

func (s *ConditionSnapshot) Kind() mflow.NodeKind

func (*ConditionSnapshot) Read

func (s *ConditionSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*ConditionSnapshot) WriteTx

func (s *ConditionSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type ExecutionParams

type ExecutionParams struct {
	Flow     mflow.Flow
	Nodes    []mflow.Node
	Edges    []mflow.Edge // Only valid edges (no orphaned source/target references)
	FlowVars []mflow.FlowVariable
}

ExecutionParams contains the flow data needed for execution.

type ExecutionResult

type ExecutionResult struct {
	Duration int32
}

ExecutionResult contains the outcome of a flow execution.

type ExecutionSession

type ExecutionSession interface {
	// Prepare builds the execution graph from flow data.
	// Must be called before Run.
	Prepare(ctx context.Context, params ExecutionParams) error

	// Run executes the prepared flow and returns the result.
	// The processor lifecycle (Start/Wait) is managed internally.
	Run(ctx context.Context) (ExecutionResult, error)
}

ExecutionSession manages a single flow execution lifecycle. Implementations may run the flow locally (ServerSession) or dispatch to remote workers for distributed execution.

type ForEachSnapshot

type ForEachSnapshot struct{ Service *sflow.NodeForEachService }

func (*ForEachSnapshot) Kind

func (s *ForEachSnapshot) Kind() mflow.NodeKind

func (*ForEachSnapshot) Read

func (s *ForEachSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*ForEachSnapshot) WriteTx

func (s *ForEachSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type ForSnapshot

type ForSnapshot struct{ Service *sflow.NodeForService }

func (*ForSnapshot) Kind

func (s *ForSnapshot) Kind() mflow.NodeKind

func (*ForSnapshot) Read

func (s *ForSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*ForSnapshot) WriteTx

func (s *ForSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type GraphQLSnapshot

type GraphQLSnapshot struct{ Service *sflow.NodeGraphQLService }

func (*GraphQLSnapshot) Kind

func (s *GraphQLSnapshot) Kind() mflow.NodeKind

func (*GraphQLSnapshot) Read

func (s *GraphQLSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*GraphQLSnapshot) WriteTx

func (s *GraphQLSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type JSSnapshot

type JSSnapshot struct{ Service *sflow.NodeJsService }

func (*JSSnapshot) Kind

func (s *JSSnapshot) Kind() mflow.NodeKind

func (*JSSnapshot) Read

func (s *JSSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*JSSnapshot) WriteTx

func (s *JSSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type LocalSessionFactory

type LocalSessionFactory struct {
	Builder  *flowbuilder.Builder
	JsClient node_js_executorv1connect.NodeJsExecutorServiceClient
}

LocalSessionFactory creates ServerSession instances for local execution.

func (*LocalSessionFactory) Create

type MemorySnapshot

type MemorySnapshot struct{ Service *sflow.NodeMemoryService }

func (*MemorySnapshot) Kind

func (s *MemorySnapshot) Kind() mflow.NodeKind

func (*MemorySnapshot) Read

func (s *MemorySnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*MemorySnapshot) WriteTx

func (s *MemorySnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type NodeConfigResult

type NodeConfigResult struct {
	NodeKind mflow.NodeKind
	Config   any // The created model (e.g., mflow.NodeFor, mflow.NodeJS)
}

NodeConfigResult holds the result of writing a single node's type-specific config.

type NodeConfigSnapshot

type NodeConfigSnapshot interface {
	Kind() mflow.NodeKind
	// Read fetches the type-specific config for a node. Returns (nil, nil) if none exists.
	Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)
	// WriteTx creates a copy of the config with the new node ID inside the given transaction.
	// Returns the created model (for event publishing) or (nil, nil) if skipped.
	WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)
}

NodeConfigSnapshot reads and writes a single node kind's type-specific configuration during flow version snapshots.

type RequestSnapshot

type RequestSnapshot struct{ Service *sflow.NodeRequestService }

func (*RequestSnapshot) Kind

func (s *RequestSnapshot) Kind() mflow.NodeKind

func (*RequestSnapshot) Read

func (s *RequestSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*RequestSnapshot) WriteTx

func (s *RequestSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type RunSubFlowSnapshot

type RunSubFlowSnapshot struct{ Service *sflow.NodeRunSubFlowService }

func (*RunSubFlowSnapshot) Kind

func (s *RunSubFlowSnapshot) Kind() mflow.NodeKind

func (*RunSubFlowSnapshot) Read

func (s *RunSubFlowSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*RunSubFlowSnapshot) WriteTx

func (s *RunSubFlowSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type ServerSession

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

ServerSession implements ExecutionSession for local server execution. It builds the execution graph, runs the flow via FlowLocalRunner, and delegates result processing to a ResultProcessor.

func NewServerSession

func NewServerSession(opts ServerSessionOpts) *ServerSession

NewServerSession creates a new ServerSession for local flow execution.

func (*ServerSession) Prepare

func (s *ServerSession) Prepare(ctx context.Context, params ExecutionParams) error

Prepare builds execution variables, constructs flow nodes, and creates the runner.

func (*ServerSession) Run

Run starts the result processor, executes the flow, waits for all result processing to complete, and returns the execution duration.

type ServerSessionOpts

type ServerSessionOpts struct {
	Builder   *flowbuilder.Builder
	JsClient  node_js_executorv1connect.NodeJsExecutorServiceClient
	Processor flowresult.ResultProcessor
}

ServerSessionOpts configures a ServerSession.

type SessionFactory

type SessionFactory interface {
	Create(processor flowresult.ResultProcessor) ExecutionSession
}

SessionFactory creates ExecutionSession instances. Implementations control where the flow runs: locally (LocalSessionFactory) or on remote workers for distributed execution.

type SnapshotRegistry

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

SnapshotRegistry maps node kinds to their snapshot handlers.

func NewSnapshotRegistry

func NewSnapshotRegistry() *SnapshotRegistry

NewSnapshotRegistry creates an empty registry.

func (*SnapshotRegistry) Get

Get returns the snapshot handler for a node kind, if registered. Returns (nil, false) if the registry is nil or the kind is not registered.

func (*SnapshotRegistry) ReadAll

func (r *SnapshotRegistry) ReadAll(ctx context.Context, nodes []mflow.Node, logger interface{ Warn(msg string, args ...any) }) map[idwrap.IDWrap]any

ReadAll reads type-specific configurations for all nodes that have registered handlers. Returns a map from node ID to the config value. Errors are logged and the node is skipped (resulting in default config when written).

func (*SnapshotRegistry) Register

func (r *SnapshotRegistry) Register(s NodeConfigSnapshot)

Register adds a snapshot handler for a node kind.

func (*SnapshotRegistry) WriteAllTx

func (r *SnapshotRegistry) WriteAllTx(
	ctx context.Context,
	tx *sql.Tx,
	sourceNodes []mflow.Node,
	nodeIDMapping map[string]idwrap.IDWrap,
	configs map[idwrap.IDWrap]any,
) ([]NodeConfigResult, error)

WriteAllTx writes type-specific configurations for all nodes within a transaction. Uses configs from ReadAll. Returns the created configs for event publishing.

type SubFlowReturnSnapshot

type SubFlowReturnSnapshot struct {
	Service *sflow.NodeSubFlowReturnService
}

func (*SubFlowReturnSnapshot) Kind

func (*SubFlowReturnSnapshot) Read

func (s *SubFlowReturnSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*SubFlowReturnSnapshot) WriteTx

func (s *SubFlowReturnSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type SubFlowTriggerSnapshot

type SubFlowTriggerSnapshot struct {
	Service *sflow.NodeSubFlowTriggerService
}

func (*SubFlowTriggerSnapshot) Kind

func (*SubFlowTriggerSnapshot) Read

func (s *SubFlowTriggerSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*SubFlowTriggerSnapshot) WriteTx

func (s *SubFlowTriggerSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type WaitSnapshot

type WaitSnapshot struct{ Service *sflow.NodeWaitService }

func (*WaitSnapshot) Kind

func (s *WaitSnapshot) Kind() mflow.NodeKind

func (*WaitSnapshot) Read

func (s *WaitSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*WaitSnapshot) WriteTx

func (s *WaitSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type WsConnectionSnapshot

type WsConnectionSnapshot struct {
	Service *sflow.NodeWsConnectionService
}

func (*WsConnectionSnapshot) Kind

func (*WsConnectionSnapshot) Read

func (s *WsConnectionSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*WsConnectionSnapshot) WriteTx

func (s *WsConnectionSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

type WsSendSnapshot

type WsSendSnapshot struct{ Service *sflow.NodeWsSendService }

func (*WsSendSnapshot) Kind

func (s *WsSendSnapshot) Kind() mflow.NodeKind

func (*WsSendSnapshot) Read

func (s *WsSendSnapshot) Read(ctx context.Context, nodeID idwrap.IDWrap) (any, error)

func (*WsSendSnapshot) WriteTx

func (s *WsSendSnapshot) WriteTx(ctx context.Context, tx *sql.Tx, newNodeID idwrap.IDWrap, config any) (any, error)

Jump to

Keyboard shortcuts

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