runtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 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 runtime schedules message delivery across a flow graph.

The scheduling model is the main departure from Node-RED. Node-RED runs everything on one event loop and puts a setImmediate between every wire hop, so a message crossing five nodes yields to the loop five times and a CPU-heavy node stalls the editor, the HTTP endpoints and every other flow. Its send queue is also unbounded: a fast source outruns a slow sink until the process dies (node-red#855).

Emberwire gives each node instance its own goroutine and its own bounded inbox. Within a node, messages are handled strictly in order, so a node keeps state across messages without locking. Across nodes, work runs in parallel. When an inbox fills, the configured overflow policy decides what gives — and something always gives, visibly, rather than the process growing until the kubelet kills it.

Index

Constants

View Source
const (
	DefaultInboxCapacity = 1024
	DefaultBlockTimeout  = 30 * time.Second
	DefaultCloseTimeout  = 15 * time.Second
)

Defaults applied when Options leaves a field zero.

View Source
const (
	TypeCatch    = "catch"
	TypeStatus   = "status"
	TypeComplete = "complete"
)

Node types with runtime-wide routing behaviour rather than ordinary wiring.

View Source
const (
	TopicStatus  = "status"
	TopicError   = "error"
	TopicDropped = "dropped"
	TopicLog     = "log"
	TopicDebug   = "debug"
)

Event topics.

Variables

View Source
var ErrBlockTimeout = errors.New("timed out waiting for space in a node inbox")

ErrBlockTimeout is raised when OverflowBlock waits longer than the configured timeout. A flow graph may legally contain a cycle, and a cycle of full inboxes under a blocking policy would deadlock permanently; bounding the wait turns that into a reported error instead of a wedged runtime.

View Source
var ErrInboxFull = errors.New("node inbox is full")

ErrInboxFull is raised under OverflowError when a target inbox is full.

Functions

This section is empty.

Types

type Event

type Event struct {
	Topic string         `json:"topic"`
	Data  map[string]any `json:"data"`
	At    time.Time      `json:"at"`
}

Event is something the runtime wants the editor to know about: a status change, a debug message, a dropped message, a log line.

type Options

type Options struct {
	// InboxCapacity is how many messages may queue for one node. Zero uses
	// DefaultInboxCapacity.
	InboxCapacity int

	// Overflow is the default policy for nodes that do not override it.
	Overflow OverflowPolicy

	// BlockTimeout bounds how long OverflowBlock waits before giving up.
	BlockTimeout time.Duration

	// CloseTimeout bounds how long a node may take to shut down. Node-RED
	// waited indefinitely until 0.17 and now allows 15 seconds; a node that
	// will not close must not be able to wedge a deploy.
	CloseTimeout time.Duration

	// Now is the clock, injectable for tests.
	Now func() time.Time
}

Options tunes the scheduler.

type OverflowPolicy

type OverflowPolicy string

OverflowPolicy decides what happens when a node's inbox is full.

const (
	// OverflowBlock makes the sender wait, propagating back-pressure upstream
	// to the source. This is the default because it is the only policy that
	// does not lose data.
	OverflowBlock OverflowPolicy = "block"

	// OverflowDropNewest discards the arriving message. Correct for sampling a
	// high-rate sensor feed where the freshest reading is not sacred.
	OverflowDropNewest OverflowPolicy = "drop-newest"

	// OverflowDropOldest evicts the oldest queued message to make room. Correct
	// when only the latest value matters, such as a display update.
	OverflowDropOldest OverflowPolicy = "drop-oldest"

	// OverflowError raises an error to the nearest Catch node instead of
	// queueing, letting the flow decide.
	OverflowError OverflowPolicy = "error"
)

func (OverflowPolicy) Valid

func (p OverflowPolicy) Valid() bool

Valid reports whether p is a recognised policy.

type Runtime

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

Runtime owns a running flow graph.

func New

func New(reg *node.Registry, flows *engine.Flows, opts Options) *Runtime

New builds a runtime for a parsed flow set. Nothing starts until Start.

func (*Runtime) Events

func (rt *Runtime) Events() <-chan Event

Events returns the channel the editor subscribes to. The channel is buffered; when it fills, events are dropped rather than blocking message delivery, because a slow editor must never be able to stall the plant floor.

func (*Runtime) Inject

func (rt *Runtime) Inject(nodeID string, msg *engine.Msg) error

Inject pushes a message into a node from outside the graph. Used by the editor's manual Inject button and by tests.

func (*Runtime) Instances

func (rt *Runtime) Instances() []string

Instances returns the scope id of every expanded subflow instance.

func (*Runtime) NodeStatus

func (rt *Runtime) NodeStatus(nodeID string) (node.Status, bool)

NodeStatus returns the retained badge for a node.

func (*Runtime) Publish

func (rt *Runtime) Publish(e Event)

Publish sends an arbitrary event to subscribers. The Debug node uses it.

func (*Runtime) Running

func (rt *Runtime) Running(nodeID string) bool

Running reports whether a node id has a live runner.

func (*Runtime) SetContexts

func (rt *Runtime) SetContexts(c *store.ScopedContexts)

SetContexts replaces the context stores, which is how a persistent store is substituted for the default in-memory one.

func (*Runtime) SetCredentials

func (rt *Runtime) SetCredentials(fn func(nodeID string) map[string]string)

SetCredentials installs the lookup used to hand a node its decrypted secrets.

func (*Runtime) SetMetricsHooks

func (rt *Runtime) SetMetricsHooks(execTime, queueLatency func(nodeID, typ string, d time.Duration))

SetMetricsHooks installs optional observers for per-node timings.

func (*Runtime) Snapshots

func (rt *Runtime) Snapshots() []Snapshot

Snapshots returns per-node counters for every running node, sorted by id.

func (*Runtime) Start

func (rt *Runtime) Start(ctx context.Context) []StartError

Start builds and starts every enabled node.

It returns the per-node failures it tolerated. A non-nil slice does not mean the runtime failed to start.

func (*Runtime) Stop

func (rt *Runtime) Stop(ctx context.Context) []error

Stop shuts the runtime down: sources first so nothing new is produced, then inboxes drain, then resources are released.

func (*Runtime) Warnings

func (rt *Runtime) Warnings() []string

Warnings returns anything the subflow expansion found worth saying: a template declaring more inputs than a v1 wire can address, an output wired from a node that is not in the template, a subflow that contains itself.

type Snapshot

type Snapshot struct {
	NodeID    string `json:"nodeId"`
	Type      string `json:"type"`
	Received  int64  `json:"received"`
	Sent      int64  `json:"sent"`
	Errors    int64  `json:"errors"`
	Dropped   int64  `json:"dropped"`
	Blocked   int64  `json:"blocked"`
	QueueLen  int    `json:"queueLen"`
	QueueCap  int    `json:"queueCap"`
	QueueHigh int64  `json:"queueHigh"`
}

Snapshot is a point-in-time copy of a node's counters.

type StartError

type StartError struct {
	NodeID string
	Type   string
	Err    error
}

StartError records a node that failed to build or start. A failure is scoped to the one node: the rest of the flow still runs, and the editor is told which node is broken. Failing the whole deploy because one node's config is wrong is how a single typo takes a line down.

func (StartError) Error

func (e StartError) Error() string

type Stats

type Stats struct {
	Received  atomic.Int64
	Sent      atomic.Int64
	Errors    atomic.Int64
	Dropped   atomic.Int64
	Blocked   atomic.Int64
	QueueHigh atomic.Int64
}

Stats are the per-node counters the metrics endpoint and the editor's status badge read. Counters are read with atomics so a scrape never blocks delivery.

Jump to

Keyboard shortcuts

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