runner

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package runner executes a compiled pipeline.Plan: one goroutine per node, bounded pipes with blocking backpressure between nodes, broadcast of immutable batches to every enabled consumer, explicit draining of discarded outputs, fail-fast cancellation that unblocks every wait, and a structured run report. Diagnostics, progress and previews are delivered through callbacks and never enter data streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchReport

type BatchReport struct {
	// Batches is the number of batches delivered to the implementation.
	Batches int `json:"batches"`
	// MaxBatchItems is the size of the largest batch and AvgBatchItems the
	// mean size (items delivered / batches; 0 when there was none).
	MaxBatchItems int     `json:"maxBatchItems"`
	AvgBatchItems float64 `json:"avgBatchItems"`
	// WaitFlushes counts batches delivered below maxItems because maxWaitMs
	// had elapsed (with maxWaitMs 0: every batch that was neither full nor
	// the remainder), MaxFlushes those that held maxItems items, EOFFlushes
	// the remainder at the end of the input.
	WaitFlushes int `json:"waitFlushes"`
	MaxFlushes  int `json:"maxFlushes"`
	EOFFlushes  int `json:"eofFlushes"`
	// HighWaterItems is the largest number of items held for the node at one
	// time: the batch in flight plus the accumulating one (≤ 2 × maxItems).
	HighWaterItems int `json:"highWaterItems"`
}

BatchReport describes how a node in batch mode received its input (pipeline/v0.1 section 10; experimental). Every delivered batch is counted under exactly one of the three flush reasons.

type BufferReport

type BufferReport struct {
	Capacity  int
	HighWater int
}

BufferReport describes the bounded buffer of one edge, in batches.

type Func

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

Func calls a function-like pipe as a scalar function: one input item in, exactly one output item out. The pipe is compiled once and kept running; each Call hands one item to it and waits for the result. A Func is safe for sequential use only (one Call at a time). Close it when done.

func NewFunc

func NewFunc(ctx context.Context, m *manifest.Manifest, params map[string]any, o FuncOptions) (*Func, error)

NewFunc prepares a function-like pipe (manifest.IsFunctionLike) for repeated scalar calls. It refuses pipes that are not function-like, that need any permission, or that do not execute entirely in-process. The returned Func lives until Close or until ctx is done.

func (*Func) Call

func (f *Func) Call(ctx context.Context, item stream.Item) (stream.Item, error)

Call applies the pipe to one item.

func (*Func) Close

func (f *Func) Close() error

Close stops the pipe and releases its goroutines. It returns the pipe's failure, if it failed before being closed.

type FuncOptions

type FuncOptions struct {
	// Registry provides the adapters. Required.
	Registry *adapter.Registry
	// Resolver resolves references of composite pipes (default: local paths,
	// std: and builtin:).
	Resolver pipeline.Resolver
	// EvalExpr evaluates `$expr` bindings inside composites.
	EvalExpr func(ctx context.Context, expr string, params map[string]any) (any, error)
}

FuncOptions configures NewFunc.

type NodeProgress

type NodeProgress struct {
	ID         string `json:"id"`
	State      State  `json:"state"`
	RecordsIn  int64  `json:"recordsIn"`
	RecordsOut int64  `json:"recordsOut"`
	BytesIn    int64  `json:"bytesIn"`
	BytesOut   int64  `json:"bytesOut"`
}

NodeProgress is one node's live counters in a Snapshot.

type NodeReport

type NodeReport struct {
	State      State          `json:"state"`
	DurationMs int64          `json:"durationMs"`
	Ports      PortsReport    `json:"ports"`
	Usage      map[string]any `json:"usage,omitempty"`
	// Batch holds the batch statistics of a node in batch mode.
	Batch *BatchReport `json:"batch,omitempty"`
}

NodeReport is the per-node part of a Report. Nested nodes of composites appear under their path, e.g. "outer/inner".

type Options

type Options struct {
	// Inputs binds the plan's external inputs by name. A missing optional
	// input is an empty stream; a missing required input fails the run with
	// E_UNCONNECTED before anything starts.
	Inputs map[string]stream.Reader
	// Outputs binds the plan's enabled external outputs by name. A missing
	// binding fails with E_UNCONNECTED unless DiscardUnbound is set.
	Outputs map[string]stream.Writer
	// DiscardUnbound drains enabled outputs that have no binding.
	DiscardUnbound bool
	// Diagnostics receives out-of-band messages from nodes and the runner.
	// Calls are serialised.
	Diagnostics func(adapter.Diagnostic)
	// Tap observes batches as they are produced (see Tap, Preview).
	Tap Tap
	// Progress, when set, is called every ProgressInterval (default 200 ms)
	// and once at the end with Final set.
	Progress         func(Snapshot)
	ProgressInterval time.Duration
	// PipeCapacity is the number of batches buffered per edge (default
	// stream.DefaultPipeCapacity = 64).
	PipeCapacity int
	// RunID overrides the generated run id.
	RunID string
	// Clock drives the maxWaitMs timers of nodes in batch mode (default: real
	// time). Tests inject a manual clock.
	Clock stream.Clock
}

Options configures one Run.

type PortReport

type PortReport struct {
	State   PortState `json:"state"`
	Records int64     `json:"records"`
	Bytes   int64     `json:"bytes"`
}

PortReport holds the final state and counters of one port. Bytes counts item payload bytes (excluding NDJSON line terminators).

type PortState

type PortState string

PortState is the state of one port during/after a run.

const (
	PortDisconnected PortState = "disconnected"
	PortConnected    PortState = "connected" // connected, no data yet
	PortActive       PortState = "active"
	PortCompleted    PortState = "completed"
	PortFailed       PortState = "failed"
)

Port states.

type PortsReport

type PortsReport struct {
	Inputs  map[string]*PortReport `json:"inputs"`
	Outputs map[string]*PortReport `json:"outputs"`
}

PortsReport groups port reports by direction.

type Preview

type Preview struct {
	// Limit is the number of items kept per point.
	Limit int
	// MaxItemBytes skips the capture of larger items (they count as
	// truncated). 0 means 1 MiB.
	MaxItemBytes int
	// Only, when non-nil, restricts capture to the listed points.
	Only map[TapPoint]bool
	// contains filtered or unexported fields
}

Preview is a bounded Tap that keeps the first Limit items produced at each tap point (every node output and every pipeline input). Memory is bounded by Limit × MaxItemBytes per point; once a point is full the runner stops calling the tap for it, so the steady-state overhead is zero.

pv := runner.NewPreview(20)
rep, err := runner.Run(ctx, plan, runner.Options{Tap: pv, ...})
items := pv.Items(runner.TapPoint{Node: "mask", Port: "email"})

func NewPreview

func NewPreview(limit int) *Preview

NewPreview creates a Preview keeping the first limit items per point.

func (*Preview) Items

func (p *Preview) Items(at TapPoint) []stream.Item

Items returns the items captured at a point.

func (*Preview) Observe

func (p *Preview) Observe(at TapPoint, b stream.Batch) bool

Observe implements Tap.

func (*Preview) Points

func (p *Preview) Points() []TapPoint

Points lists every point that produced at least one batch.

func (*Preview) Truncated

func (p *Preview) Truncated(at TapPoint) bool

Truncated reports whether more items than captured passed the point (or an oversized item was skipped).

type Report

type Report struct {
	RunID         string                 `json:"runId"`
	State         State                  `json:"state"`
	StartedAt     time.Time              `json:"startedAt"`
	DurationMs    int64                  `json:"durationMs"`
	Error         *errs.Error            `json:"error,omitempty"`
	PartialOutput bool                   `json:"partialOutput"`
	Nodes         map[string]*NodeReport `json:"nodes"`
	Conversions   []pipeline.Conversion  `json:"conversions"`

	// Inputs and Outputs hold the counters of the pipeline's external ports.
	// They are not part of the baseline JSON shape.
	Inputs  map[string]*PortReport `json:"-"`
	Outputs map[string]*PortReport `json:"-"`
	// Duration is the precise run duration.
	Duration time.Duration `json:"-"`
	// Buffers reports, per internal edge ("from -> to"), the capacity of its
	// bounded buffer and the largest number of batches ever queued in it.
	// Not part of the JSON shape; used to verify bounded memory.
	Buffers map[string]BufferReport `json:"-"`
}

Report is the run report of baseline §3. It marshals to exactly that JSON shape: {runId, state, startedAt, durationMs, error, partialOutput, nodes, conversions}.

func Run

func Run(ctx context.Context, plan *pipeline.Plan, opts Options) (*Report, error)

Run executes the plan and blocks until it reaches a terminal state. The Report is always returned. The error is nil when the run completed, and a *errs.Error otherwise (E_CANCELLED / E_TIMEOUT when ctx ended the run, the first node failure otherwise). When Run returns, every goroutine it started has exited.

type Snapshot

type Snapshot struct {
	Elapsed time.Duration  `json:"elapsed"`
	Nodes   []NodeProgress `json:"nodes"` // plan order, nested nodes after their parent
	Final   bool           `json:"final"`
}

Snapshot is a point-in-time view of a run for progress display.

type State

type State string

State is a run or node state.

const (
	Pending   State = "pending"
	Running   State = "running"
	Completed State = "completed"
	Failed    State = "failed"
	Cancelled State = "cancelled"
)

Run and node states.

type Tap

type Tap interface {
	Observe(at TapPoint, b stream.Batch) (more bool)
}

Tap observes produced batches. Observe is called synchronously on the producer's goroutine, so it must be fast and must not block; batches are immutable and may be retained. Returning false tells the runner to stop calling the tap for that point (bounded capture). Observe may be called concurrently for different points.

type TapPoint

type TapPoint struct {
	Node string
	Port string
}

TapPoint identifies where a batch was observed: a node output (Node="mask", Port="email") or a pipeline input (Node="", Port="email"). Node is the full path for nested nodes ("outer/inner").

func (TapPoint) String

func (t TapPoint) String() string

Jump to

Keyboard shortcuts

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