interfaces

package
v0.3.39 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package interfaces defines shared interface types used across the workflow engine, handlers, and module packages. Placing these interfaces here breaks the direct handler→module concrete-type dependency and enables each package to be tested in isolation with mocks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventEmitter

type EventEmitter interface {
	EmitWorkflowStarted(ctx context.Context, workflowType, action string, data map[string]any)
	EmitWorkflowCompleted(ctx context.Context, workflowType, action string, duration time.Duration, results map[string]any)
	EmitWorkflowFailed(ctx context.Context, workflowType, action string, duration time.Duration, err error)
}

EventEmitter publishes workflow lifecycle events. *module.WorkflowEventEmitter satisfies this interface. All methods must be safe to call when no event bus is configured (no-ops).

type EventRecorder

type EventRecorder interface {
	RecordEvent(ctx context.Context, executionID string, eventType string, data map[string]any) error
}

EventRecorder records pipeline execution events for observability. *store.EventRecorderAdapter and any compatible recorder satisfy this interface.

type MetricsRecorder

type MetricsRecorder interface {
	RecordWorkflowExecution(workflowType, action, status string)
	RecordWorkflowDuration(workflowType, action string, duration time.Duration)
}

MetricsRecorder records workflow execution metrics. *module.MetricsCollector satisfies this interface. All methods must be safe to call when no metrics backend is configured (no-ops).

type PipelineContext added in v0.3.39

type PipelineContext struct {
	// TriggerData is the original data from the trigger (immutable after creation).
	TriggerData map[string]any

	// StepOutputs maps step-name -> output from each completed step.
	StepOutputs map[string]map[string]any

	// Current is the merged state: trigger data + all step outputs.
	// Steps read from Current and their output is merged back into it.
	Current map[string]any

	// Metadata holds execution metadata (pipeline name, trace ID, etc.)
	Metadata map[string]any
}

PipelineContext carries data through a pipeline execution.

func NewPipelineContext added in v0.3.39

func NewPipelineContext(triggerData map[string]any, metadata map[string]any) *PipelineContext

NewPipelineContext creates a PipelineContext initialized with trigger data.

func (*PipelineContext) MergeStepOutput added in v0.3.39

func (pc *PipelineContext) MergeStepOutput(stepName string, output map[string]any)

MergeStepOutput records a step's output and merges it into Current.

type PipelineRunner

type PipelineRunner interface {
	// Run executes the pipeline with the given trigger data and returns the
	// merged result map (equivalent to PipelineContext.Current).
	Run(ctx context.Context, data map[string]any) (map[string]any, error)

	// SetLogger sets the logger used for pipeline execution.
	// Implementations should be idempotent: if a logger is already set,
	// a subsequent call should be a no-op.
	SetLogger(logger *slog.Logger)

	// SetEventRecorder sets the recorder used for pipeline execution events.
	// Implementations should be idempotent: if a recorder is already set,
	// a subsequent call should be a no-op.
	SetEventRecorder(recorder EventRecorder)
}

PipelineRunner is the interface satisfied by *module.Pipeline. It allows workflow handlers to execute pipelines without importing the concrete module types, enabling handler unit tests with mocks.

type PipelineStep added in v0.3.39

type PipelineStep interface {
	// Name returns the step's unique name within the pipeline.
	Name() string

	// Execute runs the step with the pipeline context.
	Execute(ctx context.Context, pc *PipelineContext) (*StepResult, error)
}

PipelineStep is a single composable unit of work in a pipeline.

type Reconfigurable added in v0.2.20

type Reconfigurable interface {
	// Reconfigure applies new configuration to a running module.
	// The module should:
	//   1. Validate the new config
	//   2. Gracefully drain in-flight work
	//   3. Apply the new configuration
	//   4. Resume accepting new work
	// Returns an error if the new config is invalid or cannot be applied.
	Reconfigure(ctx context.Context, newConfig map[string]any) error
}

Reconfigurable is optionally implemented by modules that support runtime reconfiguration without requiring a full engine restart. When a config change affects only modules implementing this interface, the engine can perform a surgical update instead of a full stop/rebuild/start.

type SchemaRegistrar

type SchemaRegistrar interface {
	// Name returns the module name (used for logging).
	Name() string

	// RegisterAdminSchemas registers all admin API request/response schemas
	// onto this generator. Equivalent to calling module.RegisterAdminSchemas(gen).
	RegisterAdminSchemas()

	// ApplySchemas applies all previously registered component schemas and
	// operation schema overrides to the current OpenAPI spec.
	ApplySchemas()
}

SchemaRegistrar is implemented by any service that can register admin schemas into an OpenAPI specification and apply them. Using this interface in cmd/server allows the server to enrich the OpenAPI spec without holding a concrete *module.OpenAPIGenerator pointer.

*module.OpenAPIGenerator satisfies this interface.

type StepRegistrar added in v0.3.39

type StepRegistrar interface {
	StepRegistryProvider
	// Create instantiates a PipelineStep of the given type.
	// app must be a modular.Application; it is typed as any to avoid
	// coupling this interfaces package to the modular dependency.
	Create(stepType, name string, config map[string]any, app any) (PipelineStep, error)
}

StepRegistrar manages step type registration and creation. It embeds StepRegistryProvider for type enumeration and adds a Create method for instantiating steps. Register is intentionally omitted from this interface because factory signatures use modular.Application (a concrete type) which cannot be expressed here without creating an import cycle.

type StepRegistryProvider

type StepRegistryProvider interface {
	// Types returns all registered step type names.
	Types() []string
}

StepRegistryProvider exposes the step types registered in a step registry. *module.StepRegistry satisfies this interface.

type StepResult added in v0.3.39

type StepResult struct {
	// Output is the data produced by this step.
	Output map[string]any

	// NextStep overrides the default next step (for conditional routing).
	// Empty string means continue to the next step in sequence.
	NextStep string

	// Stop indicates the pipeline should stop after this step (success).
	Stop bool
}

StepResult is the output of a single pipeline step execution.

type Trigger

type Trigger interface {
	modular.Module
	modular.Startable
	modular.Stoppable

	// Configure sets up the trigger from configuration.
	Configure(app modular.Application, triggerConfig any) error
}

Trigger defines what can start a workflow execution. Moving this interface here breaks the engine→module import dependency while preserving backward compatibility via the type alias in the module package.

*module.HTTPTrigger, *module.ScheduleTrigger, and other concrete trigger implementations all satisfy this interface.

type TriggerRegistrar

type TriggerRegistrar interface {
	// RegisterTrigger adds a trigger to the registry.
	RegisterTrigger(trigger Trigger)
}

TriggerRegistrar manages registered triggers. *module.TriggerRegistry satisfies this interface.

type WorkflowStoreProvider

type WorkflowStoreProvider interface {
	// Name returns the module name (used for logging).
	Name() string

	// WorkflowStore returns the underlying workflow data store as an opaque
	// value. The caller is responsible for asserting the concrete type
	// (typically *module.V1Store) when further operations are required.
	WorkflowStore() any
}

WorkflowStoreProvider is implemented by any service that exposes a workflow data store. Using this interface in cmd/server decouples the server startup code from the concrete *module.WorkflowRegistry type.

*module.WorkflowRegistry satisfies this interface.

Jump to

Keyboard shortcuts

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