workflow

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package workflow implements a state machine engine for task progression. Workflows are pure data — this package has no database dependency.

Index

Constants

View Source
const SchemaJSON = `` /* 2532-byte string literal not displayed */

SchemaJSON is the JSON Schema for workflow definitions. It validates structure and types; semantic rules (reachability, cross-references between states and transitions) are checked separately in Parse().

Variables

View Source
var DefaultWorkflowJSON = json.RawMessage(`{
	"states": ["backlog", "in_progress", "review", "done", "cancelled"],
	"initial_state": "backlog",
	"terminal_states": ["done", "cancelled"],
	"transitions": [
		{"from": "backlog", "to": "in_progress", "name": "start"},
		{"from": "in_progress", "to": "review", "name": "submit"},
		{"from": "review", "to": "done", "name": "approve"},
		{"from": "review", "to": "in_progress", "name": "reject"}
	],
	"from_all": [
		{"to": "cancelled", "name": "cancel"}
	]
}`)

DefaultWorkflowJSON is the built-in workflow template:

backlog → in_progress → review → done
              ↑            │
              └────────────┘ (reject)
         fromAll → cancelled

Functions

This section is empty.

Types

type HealthIssue

type HealthIssue struct {
	State   string `json:"state"`
	Problem string `json:"problem"` // "orphaned" (state not in workflow) or "stuck" (no outbound transitions)
	Count   int    `json:"count"`
}

HealthIssue describes a problem found during a workflow health check.

type Transition

type Transition struct {
	Name string `json:"name"`
	From string `json:"from"`
	To   string `json:"to"`
}

Transition is an expanded, resolved transition between two states.

type Workflow

type Workflow struct {
	States         []string     `json:"states"`
	InitialState   string       `json:"initial_state"`
	TerminalStates []string     `json:"terminal_states"`
	Transitions    []Transition `json:"transitions"`
}

Workflow is a parsed, validated, and expanded state machine.

func Parse

func Parse(data json.RawMessage) (*Workflow, error)

Parse parses a JSON workflow definition, validates it, and expands fromAll/toAll shorthands into concrete transitions.

Validation happens in two stages:

  1. Schema validation (structure, types, required fields) via JSON Schema
  2. Semantic validation (cross-references, reachability) via custom checks

func (*Workflow) AvailableTransitions

func (w *Workflow) AvailableTransitions(currentState string) []Transition

AvailableTransitions returns the transitions available from the given state.

func (*Workflow) ExecuteTransition

func (w *Workflow) ExecuteTransition(currentState, transitionName string) (string, error)

ExecuteTransition attempts to apply the named transition from the current state. Returns the new state, or an error describing why the transition is not allowed.

func (*Workflow) HealthCheck

func (w *Workflow) HealthCheck(taskStates []string) []HealthIssue

HealthCheck compares the workflow definition against actual task states and reports orphaned states (tasks in states not in the workflow) and stuck states (tasks in non-terminal states with no outbound transitions).

func (*Workflow) IsTerminal

func (w *Workflow) IsTerminal(state string) bool

IsTerminal returns true if the given state is a terminal state.

Jump to

Keyboard shortcuts

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