factory

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: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRuntimePayload added in v0.0.5

func CloneRuntimePayload(payload []byte) []byte

CloneRuntimePayload returns a detached copy of runtime payload bytes while preserving nil for absent input.

func CloneRuntimeRelations added in v0.0.5

func CloneRuntimeRelations(relations []interfaces.Relation) []interfaces.Relation

CloneRuntimeRelations returns a detached copy of runtime relations while preserving nil for absent input.

func CloneRuntimeTags added in v0.0.5

func CloneRuntimeTags(tags map[string]string) map[string]string

CloneRuntimeTags returns a detached copy of runtime tag metadata while preserving nil for absent input.

Types

type APIFactory

type APIFactory interface {
	// SubmitWorkRequest injects a canonical work request batch idempotently.
	SubmitWorkRequest(ctx context.Context, request interfaces.WorkRequest) (interfaces.WorkRequestSubmitResult, error)

	// SubscribeFactoryEvents returns canonical factory event history followed by
	// live events. The live stream closes when ctx is canceled.
	SubscribeFactoryEvents(ctx context.Context) (*interfaces.FactoryEventStream, error)

	// GetEngineStateSnapshot returns the aggregate observability snapshot for
	// service-facing consumers.
	GetEngineStateSnapshot(ctx context.Context) (*interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *state.Net], error)
}

APIFactory is the factory boundary required by the HTTP API server.

type Clock

type Clock interface {
	Now() time.Time
}

Clock is the runtime time source used by replay-sensitive factory paths.

func EnsureClock

func EnsureClock(clock Clock) Clock

EnsureClock returns a real clock when the supplied clock is nil.

type CompletionDeliveryPlanner

type CompletionDeliveryPlanner interface {
	DeliveryTickForDispatch(dispatch interfaces.WorkDispatch) (int, bool, error)
}

CompletionDeliveryPlanner maps a runtime dispatch to the logical tick at which a completed worker result may become visible.

type CompletionRecorder

type CompletionRecorder func(interfaces.FactoryCompletionRecord)

CompletionRecorder receives completed worker results after dispatch/result hooks make them visible to the engine at a logical tick boundary.

type DispatchRecorder

type DispatchRecorder func(interfaces.FactoryDispatchRecord)

DispatchRecorder receives authoritative dispatch observations from the engine after in-flight tracking is updated and before worker submission.

type DispatchResultHook

type DispatchResultHook interface {
	SubmitDispatch(ctx context.Context, dispatch interfaces.WorkDispatch) error
	OnTick(ctx context.Context, snapshot interfaces.EngineStateSnapshot[petri.MarkingSnapshot, *state.Net]) ([]interfaces.WorkResult, error)
	WaitCh() <-chan struct{}
}

DispatchResultHook bridges engine-owned dispatch creation with worker execution and tick-owned result delivery.

type Factory

type Factory interface {
	WorkMover
	// Run starts the factory loop. Blocks until ctx is cancelled or all
	// work reaches terminal states.
	Run(ctx context.Context) error

	APIFactory

	// Pause pauses the factory loop. No transitions fire until resumed.
	Pause(ctx context.Context) error

	// GetFactoryEvents returns the current-process canonical event history.
	GetFactoryEvents(ctx context.Context) ([]factoryapi.FactoryEvent, error)

	// WaitToComplete returns a channel that is closed when all tokens reach
	// terminal or failed places and no dispatches are in flight. Callers can
	// block on this channel to know when the factory has finished all work
	// without having to manually drive ticks.
	WaitToComplete() <-chan struct{}
}

Factory is the top-level interface for a CPN-based workflow engine.

type FactoryConfig

type FactoryConfig struct {
	Scheduler                 scheduler.Scheduler
	WorkerExecutors           map[string]workers.WorkerExecutor
	RuntimeConfig             interfaces.RuntimeDefinitionLookup
	WorkflowContext           *factory_context.FactoryContext
	RuntimeMode               interfaces.RuntimeMode
	Logger                    logging.Logger
	Clock                     Clock
	EventHistory              *events.FactoryEventHistory
	SubmissionRecorder        SubmissionRecorder
	FactoryEventRecorder      FactoryEventRecorder
	SubmissionHooks           []SubmissionHook
	DispatchRecorder          DispatchRecorder
	CompletionRecorder        CompletionRecorder
	CompletionDeliveryPlanner CompletionDeliveryPlanner
	// contains filtered or unexported fields
}

FactoryConfig holds all configurable settings for factory construction. Fields are set via functional options (With* functions). The net field is package-private; use GetNet() to read it from outside the package.

func (*FactoryConfig) GetNet

func (c *FactoryConfig) GetNet() *state.Net

GetNet returns the CPN net definition.

func (*FactoryConfig) IsInlineDispatch

func (c *FactoryConfig) IsInlineDispatch() bool

IsInlineDispatch returns whether synchronous inline dispatch is enabled.

type FactoryEventRecorder

type FactoryEventRecorder func(factoryapi.FactoryEvent)

FactoryEventRecorder receives canonical generated FactoryEvent messages in append order as runtime history records them.

type FactoryOption

type FactoryOption func(*FactoryConfig)

FactoryOption configures a factoryImpl via the functional options pattern.

func WithClock

func WithClock(clock Clock) FactoryOption

WithClock sets the runtime time source used by engine and subsystem paths. Nil clocks are ignored and the runtime defaults to RealClock.

func WithCompletionDeliveryPlanner

func WithCompletionDeliveryPlanner(planner CompletionDeliveryPlanner) FactoryOption

WithCompletionDeliveryPlanner delays worker-pool completions until their planned logical tick. Dispatches without a planned tick use normal delivery.

func WithCompletionRecorder

func WithCompletionRecorder(recorder CompletionRecorder) FactoryOption

WithCompletionRecorder records worker completions at the logical tick where dispatch/result hooks return them to the engine.

func WithDispatchRecorder

func WithDispatchRecorder(recorder DispatchRecorder) FactoryOption

WithDispatchRecorder records dispatches after engine tracking is updated and before the dispatch/result hook receives the work.

func WithFactoryEventHistory

func WithFactoryEventHistory(history *events.FactoryEventHistory) FactoryOption

WithFactoryEventHistory injects a preconstructed canonical event history. This lets service wiring provide the same append surface to provider wrappers before worker executors are constructed.

func WithFactoryEventRecorder

func WithFactoryEventRecorder(recorder FactoryEventRecorder) FactoryOption

WithFactoryEventRecorder records canonical generated events as they are appended to the runtime event history.

func WithInlineDispatch

func WithInlineDispatch() FactoryOption

WithInlineDispatch enables synchronous inline dispatch mode. When enabled, dispatches are executed inline during engine ticks through the registered worker executors instead of being routed through the async worker pool. Used by the test harness for deterministic tick-based testing.

func WithLogger

func WithLogger(l logging.Logger) FactoryOption

WithLogger sets the logger for the factory. Default: no-op.

func WithNet

func WithNet(n *state.Net) FactoryOption

WithNet sets the CPN definition for the factory. Required.

func WithRuntimeConfig

func WithRuntimeConfig(runtimeCfg interfaces.RuntimeDefinitionLookup) FactoryOption

WithRuntimeConfig sets the authoritative runtime-loaded worker/workstation config used by subsystems that need AGENTS.md-backed execution metadata.

func WithRuntimeMode

func WithRuntimeMode(mode interfaces.RuntimeMode) FactoryOption

WithRuntimeMode sets the runtime lifecycle mode. Batch mode terminates on idle completion; service mode stays alive until the run context is canceled.

func WithScheduler

func WithScheduler(s scheduler.Scheduler) FactoryOption

WithScheduler sets the scheduling strategy. Default: FIFO.

func WithServiceMode

func WithServiceMode() FactoryOption

WithServiceMode keeps the runtime alive while idle so callers can submit new work after startup. This is a convenience wrapper around WithRuntimeMode.

func WithSubmissionHook

func WithSubmissionHook(hook SubmissionHook) FactoryOption

WithSubmissionHook registers a logical-tick hook that can return generated batches, work results, and work events to the engine.

func WithSubmissionRecorder

func WithSubmissionRecorder(recorder SubmissionRecorder) FactoryOption

WithSubmissionRecorder records submissions after hook output is observed and before the engine injects tokens.

func WithWorkerExecutor

func WithWorkerExecutor(workerType string, e workers.WorkerExecutor) FactoryOption

WithWorkerExecutor registers a worker executor for the given worker type.

func WithWorkflowContext

func WithWorkflowContext(wfCtx *factory_context.FactoryContext) FactoryOption

WithWorkflowContext sets execution context exposed to prompt and workstation field templates.

type LogicalClock

type LogicalClock interface {
	Clock
	SetTick(tick int)
}

LogicalClock is a clock that can align itself to the current engine tick.

type RealClock

type RealClock struct{}

RealClock reads the host wall clock.

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current wall-clock time.

type SubmissionHook

SubmissionHook provides generated work batches, results, and events that become visible to the engine at deterministic tick boundaries.

type SubmissionRecorder

type SubmissionRecorder func(interfaces.FactorySubmissionRecord)

SubmissionRecorder receives authoritative submission observations from the engine before submitted work is injected into the marking.

type WorkMover added in v0.0.5

type WorkMover interface {
	MoveWork(ctx context.Context, workID string, stateName string, source interfaces.WorkStateChangeSource, requestID string) (interfaces.OperatorMoveResult, error)
}

WorkMover is synchronous operator control ingress for relocating work tokens.

Directories

Path Synopsis
Package runtime provides the concrete Factory implementation that wires together the engine, workers, and subsystems.
Package runtime provides the concrete Factory implementation that wires together the engine, workers, and subsystems.
Package scheduler provides transition scheduling strategies for the CPN engine.
Package scheduler provides transition scheduling strategies for the CPN engine.
validation
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.
Package subsystems defines the Subsystem interface and active tick-phase components used by the runtime.
Package subsystems defines the Subsystem interface and active tick-phase components used by the runtime.
Package validationentry validates factoryapi.Factory payloads through the canonical validation package without creating an import cycle between pkg/factory/validation and pkg/config.
Package validationentry validates factoryapi.Factory payloads through the canonical validation package without creating an import cycle between pkg/factory/validation and pkg/config.

Jump to

Keyboard shortcuts

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