dsl

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dsl parses and validates Packtrail Flow Definitions (YAML) and exposes graph-walk helpers used by the runtime.

Index

Constants

View Source
const (
	NodeTask   = "task"
	NodeFanout = "fanout"
	NodeFanin  = "fanin"
	NodeChoice = "choice"
	NodeSignal = "signal"
)

Node types.

View Source
const (
	JoinAll    = "all"
	JoinAny    = "any"
	JoinQuorum = "quorum" // requires Quorum > 0
)

Join policy kinds for a fanin node.

View Source
const DefaultInvoker = "nats-task"

DefaultInvoker is the invoker kind used by a task node that does not set one. It selects packtrail's built-in NATS request/reply transport (pkg/protocol).

Variables

This section is empty.

Functions

func LoadDir

func LoadDir(dir string) (map[string]*Flow, error)

LoadDir parses every *.yaml / *.yml file in dir, keyed by flow name.

func ResolvePlaceholders

func ResolvePlaceholders(target, executionID string) string

ResolvePlaceholders substitutes the {execution_id} placeholder in a task node's target (subject, agent name, URL, …) with the concrete execution id.

Types

type Duration

type Duration time.Duration

Duration is a time.Duration that unmarshals from a YAML string like "30s" or "24h". A zero/empty value unmarshals to 0.

func (*Duration) D

func (d *Duration) D() time.Duration

D returns the value as a time.Duration.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML string like "30s" or "24h" into a Duration.

type Edge

type Edge struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`
}

Edge is a static graph edge.

type Flow

type Flow struct {
	Version string `yaml:"version"`
	Name    string `yaml:"name"`
	Nodes   []Node `yaml:"nodes"`
	Edges   []Edge `yaml:"edges"`
	// contains filtered or unexported fields
}

Flow is a parsed, validated Flow Definition.

func Parse

func Parse(data []byte) (*Flow, error)

Parse decodes and validates a Flow Definition from YAML bytes.

func ParseFile

func ParseFile(path string) (*Flow, error)

ParseFile reads and parses a Flow Definition file.

func (*Flow) Node

func (f *Flow) Node(id string) *Node

Node returns the node with the given id, or nil.

func (*Flow) StartNode

func (f *Flow) StartNode() string

StartNode returns the id of the unique node with no inbound transition.

func (*Flow) Successor

func (f *Flow) Successor(id string) string

Successor returns the id of the node reached by the single outgoing edge of id, or "" if id has no outgoing edge (a terminal node).

func (*Flow) Validate

func (f *Flow) Validate() error

Validate checks structural and semantic correctness of the flow and builds the internal indexes used by the graph-walk helpers. It is called by Parse.

type Node

type Node struct {
	ID   string `yaml:"id"`
	Type string `yaml:"type"`

	// task
	Invoker string       `yaml:"invoker"` // invocation kind; defaults to DefaultInvoker
	Target  string       `yaml:"target"`  // invoker-specific target; defaults to Subject
	Subject string       `yaml:"subject"` // nats-task subject (alias for Target)
	Timeout Duration     `yaml:"timeout"`
	Retry   *RetryPolicy `yaml:"retry"`

	// fanout
	Branches []string `yaml:"branches"`

	// fanin
	WaitFor    []string `yaml:"wait_for"`
	JoinPolicy string   `yaml:"join_policy"`

	// choice
	Rules []Rule `yaml:"rules"`

	// signal
	SignalName string `yaml:"signal_name"`
	OnTimeout  string `yaml:"on_timeout"`
}

Node is a single node in the flow graph. Fields are type-specific; Validate enforces which are required for each Type.

func (*Node) InvokeTarget

func (n *Node) InvokeTarget() string

InvokeTarget returns the invoker-specific target for a task node. Target takes precedence; Subject is kept as the alias so existing nats-task flows are unchanged.

func (*Node) InvokerKind

func (n *Node) InvokerKind() string

InvokerKind returns the invoker kind for a task node, defaulting to DefaultInvoker ("nats-task") when unset.

func (*Node) JoinKind

func (n *Node) JoinKind() (kind string, quorum int)

JoinKind returns the parsed join policy kind and, for quorum, the required count N. Defaults to JoinAll when unset.

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts int    `yaml:"max_attempts"`
	Backoff     string `yaml:"backoff"` // "exponential" | "linear" | "fixed" | "" (default fixed)
}

RetryPolicy controls task retries.

type Rule

type Rule struct {
	When    string `yaml:"when"`
	Default bool   `yaml:"default"`
	To      string `yaml:"to"`
}

Rule is one branch of a choice node. Exactly one of When / Default is set.

Jump to

Keyboard shortcuts

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