engine

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package engine provides execution infrastructure: bounded concurrent fan-out, observer dispatch, job-group execution, and simple function steps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunJobGroup

RunJobGroup executes jobs concurrently and collects all StepResults. Each job's results are forwarded to obs.OnStepComplete as they arrive. Phase-level aggregation (obs.OnPhaseComplete) is the caller's responsibility (gate.runPhase), because a serial phase invokes RunJobGroup once per job and must fire OnPhaseComplete exactly once for the whole phase. Context cancellation stops jobs that have not yet acquired a worker slot; in-flight jobs run to completion.

Types

type NopObserver

type NopObserver struct{}

NopObserver is a no-op ExecutionObserver used as a safe default.

func (NopObserver) OnGateComplete

func (NopObserver) OnGateComplete(_ string, _ types.StepResults, _ time.Duration)

OnGateComplete discards the gate-complete event.

func (NopObserver) OnGateStart

func (NopObserver) OnGateStart(_ string, _ []string)

OnGateStart discards the gate-start event.

func (NopObserver) OnPhaseComplete

func (NopObserver) OnPhaseComplete(_ string, _ types.StepResults, _ time.Duration)

OnPhaseComplete discards the phase-complete event.

func (NopObserver) OnPhaseStart

func (NopObserver) OnPhaseStart(_ string, _ []string)

OnPhaseStart discards the phase-start event.

func (NopObserver) OnStepComplete

func (NopObserver) OnStepComplete(_ types.StepResult)

OnStepComplete discards the step-complete event.

func (NopObserver) OnStepStart

func (NopObserver) OnStepStart(_, _ string)

OnStepStart discards the step-start event.

type Pool added in v0.0.7

type Pool int

Pool bounds a fan-out's concurrency: Pool(n) runs at most n items at once, and a value <= 0 means runtime.NumCPU().

func (Pool) FanOut added in v0.0.7

func (p Pool) FanOut[T any](
	ctx context.Context,
	items []T,
	fn func(ctx context.Context, item T) types.StepResult,
) types.StepResults

FanOut runs fn for each item in items with at most p items in flight.

Each invocation is isolated: a panic in fn is recovered and converted to StepResult{Status: Fail, Detail: stack} rather than crashing the process. fn returning a Fail result is passed through unchanged.

Context cancellation (via gctx derived from ctx) stops items that have not yet acquired a worker slot; items already running continue until fn returns. All results are collected -- fn always returns nil to the errgroup so no unit can cancel its siblings.

type Step

type Step struct {
	// Run is the work; a non-nil error fails the step.
	Run func(context.Context) error

	// Name identifies the step in its result.
	Name string

	// Group categorizes the step for display.
	Group string

	// WarnOnly downgrades a failure to a warning.
	WarnOnly bool
}

Step is a named function run as one unit of work, for commands that need function-to-result wrapping without a job's runner and root.

func (Step) Execute

func (s Step) Execute(ctx context.Context) types.StepResult

Execute runs the step and returns its timed result. An uncoded error is wrapped as INTERNAL so the result always carries a code.

type Steps added in v0.0.7

type Steps []Step

Steps is an ordered list of steps.

func (Steps) Serial added in v0.0.7

func (s Steps) Serial(ctx context.Context) types.StepResults

Serial runs every step in order and returns their results; a failure does not stop the steps after it.

Jump to

Keyboard shortcuts

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