orchestration

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package orchestration provides DAG-based resource lifecycle management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOutput

func GetOutput[T any](reg *OutputRegistry, handlerName string, key string) (T, bool)

GetOutput retrieves a typed output from the registry. Returns zero value if not found or type mismatch.

func Register

func Register[TInput any, TOutput any](
	r *Reconciler,
	handler Lifecycle[TInput, TOutput],
	resolver InputResolver[TInput],
	deps ...string,
)

Register adds a typed resource with its input resolver and dependency list.

Types

type InputResolver

type InputResolver[TInput any] func(reg *OutputRegistry) ([]TInput, error)

InputResolver resolves inputs for a handler using outputs from upstream handlers.

type Lifecycle

type Lifecycle[TInput any, TOutput any] interface {
	// Name returns the handler name for identification
	Name() string
	// Key generates a unique key for the given input
	Key(input TInput) string
	// Create provisions the resource using the given input
	Create(ctx context.Context, input TInput) (TOutput, error)
	// Destroy removes the resource using its output
	Destroy(ctx context.Context, output TOutput) error
	// Check verifies the resource status from its output
	Check(ctx context.Context, output TOutput) (Status, error)
	// Recover discovers a resource from its input when no lock entry exists
	Recover(ctx context.Context, input TInput) (TOutput, Status, error)
}

Lifecycle defines how to create, destroy, and check a specific resource type. TInput represents the full input (including upstream outputs). TOutput represents the runtime output after resource creation. Change detection is handled by the framework via input hashing — no Equals() needed.

type LockEntry

type LockEntry struct {
	Key         string `json:"key"`
	Data        any    `json:"data"`
	HandlerName string `json:"handler_name"`
	InputHash   string `json:"input_hash,omitempty"`
}

LockEntry represents a persisted resource snapshot in moley.lock.

type LockFile

type LockFile struct {
	Entries []LockEntry `json:"entries"`
	// contains filtered or unexported fields
}

LockFile manages persistent storage of resource snapshots in moley.lock.

func LoadLockFile

func LoadLockFile() (*LockFile, error)

LoadLockFile loads moley.lock from disk and acquires an exclusive file lock. Returns an empty LockFile if the file is missing or corrupt.

func (*LockFile) Close

func (lf *LockFile) Close() error

Close releases the file lock.

func (*LockFile) PurgeOrphans

func (lf *LockFile) PurgeOrphans(registeredHandlers map[string]bool) error

PurgeOrphans removes lock entries whose handler name is not in the registered set.

func (*LockFile) Save

func (lf *LockFile) Save() error

Save persists the lock file to disk. Safe to write directly — the exclusive flock prevents concurrent access.

type OutputRegistry

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

OutputRegistry holds outputs keyed by handler name + resource key.

type Reconciler

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

Reconciler manages the lifecycle of multiple typed resources in dependency order.

func NewReconciler

func NewReconciler() (*Reconciler, error)

NewReconciler creates a new reconciler backed by the lock file registry.

func (*Reconciler) Start

func (r *Reconciler) Start(ctx context.Context) error

Start reconciles all registered resources in topological (dependency) order.

func (*Reconciler) Stop

func (r *Reconciler) Stop(ctx context.Context) error

Stop tears down all registered resources in reverse topological order.

type Snapshot

type Snapshot[TInput any, TOutput any] struct {
	Input  TInput  `json:"input"`
	Output TOutput `json:"output"`
}

Snapshot stores both input and output for a lock entry.

type Status

type Status string

Status represents the operational status of a resource (up, down, or unknown).

const (
	StatusUp      Status = "up"
	StatusDown    Status = "down"
	StatusUnknown Status = "unknown"
)

Jump to

Keyboard shortcuts

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