state

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateResourcePlaces

func GenerateResourcePlaces(def *ResourceDef) (*petri.Place, []*interfaces.Token)

GenerateResourcePlaces produces a Place with ID '{resource_id}:available' and a slice of pre-loaded resource tokens for the given ResourceDef.

func NewEngineStateSnapshot

func NewEngineStateSnapshot(
	runtime interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *Net],
	factoryState string,
	uptime time.Duration,
	topology *Net,
) interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *Net]

NewEngineStateSnapshot builds the canonical aggregate snapshot for service-facing consumers from a raw runtime snapshot plus service lifecycle metadata.

func NormalizeTransitionTopology

func NormalizeTransitionTopology(net *Net, workstationKinds map[string]interfaces.WorkstationKind)

NormalizeTransitionTopology materializes implicit routing onto transition arc sets. Repeater workstations get rejection arcs back to their work-token inputs, and transitions without explicit failure arcs get routed to each input work type's failed state. Standard workstations without explicit rejection arcs also reject into those failed-state arcs. Runtime routing can then use a single outcome -> arc-set path.

func PlaceID

func PlaceID(workTypeID, stateValue string) string

PlaceID returns the derived place ID for a work type state. Convention: '{work_type_id}:{state_value}'.

func SplitPlaceID

func SplitPlaceID(placeID string) (workType, stateValue string)

SplitPlaceID extracts work type and state from a place ID. Place IDs follow the convention '{work_type}:{state}'.

func ValidStatesByType

func ValidStatesByType(workTypes map[string]*WorkType) map[string]map[string]bool

ValidStatesByType returns the configured state names for each work type.

Types

type GlobalLimits

type GlobalLimits struct {
	MaxTokenAge    time.Duration `json:"max_token_age"`    // max time a token can exist before being force-failed (0 = no limit)
	MaxTotalVisits int           `json:"max_total_visits"` // max total transition visits for any single token (0 = no limit)
}

GlobalLimits defines net-wide execution constraints that apply to all tokens. These are the outermost safety net — individual transitions and cycles can have tighter limits, but these catch anything that slips through.

type InputType

type InputType struct {
	Name string `json:"name"`
	Kind string `json:"kind"` // "default"
}

InputType defines a named input type available on the factory. The "default" type is always implicitly available and requires no structured payload.

type Net

type Net struct {
	ID          string                       `json:"id"`
	Places      map[string]*petri.Place      `json:"places"`
	Transitions map[string]*petri.Transition `json:"transitions"`
	Arcs        map[string]*petri.Arc        `json:"arcs"`
	WorkTypes   map[string]*WorkType         `json:"work_types"`
	Resources   map[string]*ResourceDef      `json:"resources"`
	InputTypes  map[string]*InputType        `json:"input_types,omitempty"`
	Limits      GlobalLimits                 `json:"limits"`

	// FanoutGroups maps a spawning transition ID to its fanout count place ID.
	// When the transitioner processes spawned work from a transition in this map,
	// it creates a guard token in the count place carrying the expected child count.
	FanoutGroups map[string]string `json:"fanout_groups,omitempty"`
}

Net is the complete CPN definition — places, transitions, arcs. This is loaded from the workflow config and validated at load time. The net topology is static; dynamism lives in the tokens.

func (*Net) StateCategoryForPlace

func (n *Net) StateCategoryForPlace(placeID string) StateCategory

StateCategoryForPlace returns the StateCategory for the place identified by placeID. It looks up the place's TypeID and State, then finds the matching StateDefinition in the work type. Returns StateCategoryProcessing if the place or work type is unknown.

type ResourceDef

type ResourceDef struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Capacity int    `json:"capacity"` // number of resource tokens to pre-load
}

ResourceDef defines a resource type and its capacity. Resources are modeled as places with bounded tokens. A GPU with capacity 1 = a place "gpu:available" pre-loaded with 1 token.

type StateCategory

type StateCategory string

StateCategory classifies states within a work type.

const (
	StateCategoryInitial    StateCategory = "INITIAL"
	StateCategoryProcessing StateCategory = "PROCESSING"
	StateCategoryTerminal   StateCategory = "TERMINAL"
	StateCategoryFailed     StateCategory = "FAILED"
)

func CategoryForState

func CategoryForState(workTypes map[string]*WorkType, workTypeID, stateValue string) StateCategory

CategoryForState looks up the category of a work type state from a topology. Returns StateCategoryProcessing if the work type or state is unknown.

type StateDefinition

type StateDefinition struct {
	Value    string        `json:"value"`
	Category StateCategory `json:"category"` // INITIAL, PROCESSING, TERMINAL, FAILED
}

StateDefinition defines a single state within a work type.

type WorkType

type WorkType struct {
	ID     string            `json:"id"`
	Name   string            `json:"name"`
	States []StateDefinition `json:"states"`
}

WorkType defines a type of work and its state machine.

func (*WorkType) GeneratePlaces

func (wt *WorkType) GeneratePlaces() []*petri.Place

GeneratePlaces produces a Place for each state in the work type. Place IDs follow the convention '{work_type_id}:{state_value}'.

Directories

Path Synopsis
Package validation provides static validation for CPN net definitions, including reachability, completeness, boundedness, and type safety checks.
Package validation provides static validation for CPN net definitions, including reachability, completeness, boundedness, and type safety checks.

Jump to

Keyboard shortcuts

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