Documentation
¶
Index ¶
- func HasNonModuleChanges(old, new *WorkflowConfig) bool
- func HashConfig(cfg *WorkflowConfig) (string, error)
- func IsApplicationConfig(data []byte) bool
- func MergeConfigs(primary, fragment *WorkflowConfig)
- func ResolvePathInConfig(cfg map[string]any, path string) string
- type ApplicationConfig
- type ApplicationInfo
- type CompositeSource
- type ConfigChangeEvent
- type ConfigReloader
- type ConfigSource
- type ConfigWatcher
- type DBConfigStore
- type DatabasePoller
- type DatabaseSource
- type DatabaseSourceOption
- type FileSource
- type ModuleConfig
- type ModuleConfigChange
- type ModuleConfigDiff
- type ModuleReconfigurer
- type PipelineConfig
- type PipelineStepConfig
- type PipelineTriggerConfig
- type PluginRequirement
- type RequiresConfig
- type WatcherOption
- type WorkflowConfig
- type WorkflowRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasNonModuleChanges ¶ added in v0.2.20
func HasNonModuleChanges(old, new *WorkflowConfig) bool
HasNonModuleChanges returns true if workflows, triggers, pipelines, platform config, or requirements changed between old and new (requiring full reload).
func HashConfig ¶ added in v0.2.20
func HashConfig(cfg *WorkflowConfig) (string, error)
HashConfig returns the SHA256 hex digest of the YAML-serialized config.
func IsApplicationConfig ¶ added in v0.1.6
IsApplicationConfig returns true if the YAML data contains an application-level config (i.e., has an "application" key with a "workflows" section).
func MergeConfigs ¶ added in v0.1.7
func MergeConfigs(primary, fragment *WorkflowConfig)
MergeConfigs merges a config fragment into the primary config. Modules are appended. Workflows and triggers are merged without overwriting existing keys.
Types ¶
type ApplicationConfig ¶ added in v0.1.6
type ApplicationConfig struct {
// Application holds the application-level metadata and workflow references.
Application ApplicationInfo `json:"application" yaml:"application"`
// ConfigDir is the directory of the application config file, used for resolving relative paths.
ConfigDir string `json:"-" yaml:"-"`
}
ApplicationConfig is the top-level config for a multi-workflow application. It references multiple workflow config files that share a module registry.
func LoadApplicationConfig ¶ added in v0.1.6
func LoadApplicationConfig(filepath string) (*ApplicationConfig, error)
LoadApplicationConfig loads an application config from a YAML file.
type ApplicationInfo ¶ added in v0.1.6
type ApplicationInfo struct {
// Name is the application name.
Name string `json:"name" yaml:"name"`
// Workflows lists the workflow config files that make up this application.
Workflows []WorkflowRef `json:"workflows" yaml:"workflows"`
}
ApplicationInfo holds top-level metadata about a multi-workflow application.
type CompositeSource ¶ added in v0.2.20
type CompositeSource struct {
// contains filtered or unexported fields
}
CompositeSource layers multiple ConfigSources. Later sources override earlier ones. Module-level overrides are applied by name; map keys (workflows, triggers, pipelines, platform) from later sources replace or add to those from earlier ones.
func NewCompositeSource ¶ added in v0.2.20
func NewCompositeSource(sources ...ConfigSource) *CompositeSource
NewCompositeSource creates a CompositeSource from the given sources. Sources are applied in order: sources[0] is the base, each subsequent source overlays on top of the result.
func (*CompositeSource) Hash ¶ added in v0.2.20
func (s *CompositeSource) Hash(ctx context.Context) (string, error)
Hash loads the merged config and returns its hash.
func (*CompositeSource) Load ¶ added in v0.2.20
func (s *CompositeSource) Load(ctx context.Context) (*WorkflowConfig, error)
Load loads all sources and merges them into a single WorkflowConfig.
func (*CompositeSource) Name ¶ added in v0.2.20
func (s *CompositeSource) Name() string
Name returns a human-readable identifier for this source.
type ConfigChangeEvent ¶ added in v0.2.20
type ConfigChangeEvent struct {
Source string
OldHash string
NewHash string
Config *WorkflowConfig
Time time.Time
}
ConfigChangeEvent is emitted when a ConfigSource detects a change.
type ConfigReloader ¶ added in v0.2.20
type ConfigReloader struct {
// contains filtered or unexported fields
}
ConfigReloader coordinates config change detection and engine reload decisions. It diffs old and new configs, performs partial per-module reconfiguration when possible, and falls back to a full reload when non-module sections change or modules are added/removed/non-reconfigurable.
func NewConfigReloader ¶ added in v0.2.20
func NewConfigReloader( initial *WorkflowConfig, fullReloadFn func(*WorkflowConfig) error, reconfigurer ModuleReconfigurer, logger *slog.Logger, ) (*ConfigReloader, error)
NewConfigReloader creates a ConfigReloader with the given initial config. fullReloadFn is called when a full engine restart is required. reconfigurer is optional; if nil, all module changes fall back to fullReloadFn.
func (*ConfigReloader) HandleChange ¶ added in v0.2.20
func (r *ConfigReloader) HandleChange(evt ConfigChangeEvent) error
HandleChange processes a config change event. It diffs the old and new configs, attempts per-module reconfiguration for module-only changes, and falls back to a full reload when necessary.
func (*ConfigReloader) SetReconfigurer ¶ added in v0.2.20
func (r *ConfigReloader) SetReconfigurer(reconfigurer ModuleReconfigurer)
SetReconfigurer updates the ModuleReconfigurer used for partial (per-module) reloads. This should be called after a successful full engine reload if the underlying engine (and its reconfigurer) has changed.
type ConfigSource ¶ added in v0.2.20
type ConfigSource interface {
// Load retrieves the current configuration.
Load(ctx context.Context) (*WorkflowConfig, error)
// Hash returns a content-addressable hash of the current config.
// Used for change detection without full deserialization.
Hash(ctx context.Context) (string, error)
// Name returns a human-readable identifier for this source.
Name() string
}
ConfigSource provides configuration from an arbitrary backend. Implementations must be safe for concurrent use.
type ConfigWatcher ¶ added in v0.2.20
type ConfigWatcher struct {
// contains filtered or unexported fields
}
ConfigWatcher monitors a config file for changes and invokes a callback. It watches the directory containing the file for atomic-save compatibility.
func NewConfigWatcher ¶ added in v0.2.20
func NewConfigWatcher(source *FileSource, onChange func(ConfigChangeEvent), opts ...WatcherOption) *ConfigWatcher
NewConfigWatcher creates a ConfigWatcher for the given FileSource. onChange is called with a ConfigChangeEvent whenever the config changes.
func (*ConfigWatcher) Start ¶ added in v0.2.20
func (w *ConfigWatcher) Start() error
Start begins watching the config file's directory for changes.
func (*ConfigWatcher) Stop ¶ added in v0.2.20
func (w *ConfigWatcher) Stop() error
Stop terminates the watcher and waits for the background goroutine to exit. It is safe to call Stop multiple times.
type DBConfigStore ¶ added in v0.2.20
type DBConfigStore interface {
GetConfigDocument(ctx context.Context, key string) ([]byte, error)
GetConfigDocumentHash(ctx context.Context, key string) (string, error)
PutConfigDocument(ctx context.Context, key string, data []byte) error
}
DBConfigStore is the database interface needed by DatabaseSource.
type DatabasePoller ¶ added in v0.2.20
type DatabasePoller struct {
// contains filtered or unexported fields
}
DatabasePoller periodically checks a DatabaseSource for config changes.
func NewDatabasePoller ¶ added in v0.2.20
func NewDatabasePoller(source *DatabaseSource, interval time.Duration, onChange func(ConfigChangeEvent), logger *slog.Logger) *DatabasePoller
NewDatabasePoller creates a DatabasePoller that calls onChange whenever the config stored in source changes.
func (*DatabasePoller) Start ¶ added in v0.2.20
func (p *DatabasePoller) Start(ctx context.Context) error
Start fetches the initial hash and launches the background polling goroutine.
func (*DatabasePoller) Stop ¶ added in v0.2.20
func (p *DatabasePoller) Stop()
Stop signals the polling goroutine to exit and waits for it to finish. It is safe to call Stop multiple times.
type DatabaseSource ¶ added in v0.2.20
type DatabaseSource struct {
// contains filtered or unexported fields
}
DatabaseSource loads config from a database with caching.
func NewDatabaseSource ¶ added in v0.2.20
func NewDatabaseSource(store DBConfigStore, opts ...DatabaseSourceOption) *DatabaseSource
NewDatabaseSource creates a DatabaseSource backed by the given store.
func (*DatabaseSource) Hash ¶ added in v0.2.20
func (s *DatabaseSource) Hash(ctx context.Context) (string, error)
Hash returns the SHA256 hex digest of the stored config bytes. It first tries the fast path of fetching the pre-computed hash from the database, and falls back to loading the full document if that fails. The fallback always fetches fresh data to ensure change detection is accurate.
func (*DatabaseSource) Load ¶ added in v0.2.20
func (s *DatabaseSource) Load(ctx context.Context) (*WorkflowConfig, error)
Load retrieves the current configuration, returning a cached copy if still within the refresh interval.
func (*DatabaseSource) Name ¶ added in v0.2.20
func (s *DatabaseSource) Name() string
Name returns a human-readable identifier for this source.
type DatabaseSourceOption ¶ added in v0.2.20
type DatabaseSourceOption func(*DatabaseSource)
DatabaseSourceOption configures a DatabaseSource.
func WithConfigKey ¶ added in v0.2.20
func WithConfigKey(key string) DatabaseSourceOption
WithConfigKey sets the document key used to look up config in the database.
func WithRefreshInterval ¶ added in v0.2.20
func WithRefreshInterval(d time.Duration) DatabaseSourceOption
WithRefreshInterval sets the cache TTL for the DatabaseSource.
type FileSource ¶ added in v0.2.20
type FileSource struct {
// contains filtered or unexported fields
}
FileSource loads config from a YAML file on disk.
func NewFileSource ¶ added in v0.2.20
func NewFileSource(path string) *FileSource
NewFileSource creates a FileSource that reads from the given path.
func (*FileSource) Hash ¶ added in v0.2.20
func (s *FileSource) Hash(_ context.Context) (string, error)
Hash returns the SHA256 hex digest of the raw file bytes.
func (*FileSource) Load ¶ added in v0.2.20
func (s *FileSource) Load(_ context.Context) (*WorkflowConfig, error)
Load reads the config file and returns a parsed WorkflowConfig. Supports both ApplicationConfig (multi-workflow) and WorkflowConfig formats.
func (*FileSource) Name ¶ added in v0.2.20
func (s *FileSource) Name() string
Name returns a human-readable identifier for this source.
func (*FileSource) Path ¶ added in v0.2.20
func (s *FileSource) Path() string
Path returns the filesystem path this source reads from.
type ModuleConfig ¶
type ModuleConfig struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
Config map[string]any `json:"config,omitempty" yaml:"config,omitempty"`
DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
Branches map[string]string `json:"branches,omitempty" yaml:"branches,omitempty"`
}
ModuleConfig represents a single module configuration
type ModuleConfigChange ¶ added in v0.2.20
ModuleConfigChange represents a change to a single module's config.
type ModuleConfigDiff ¶ added in v0.2.20
type ModuleConfigDiff struct {
Added []ModuleConfig // modules in new but not old
Removed []ModuleConfig // modules in old but not new
Modified []ModuleConfigChange // modules present in both with different config
Unchanged []string // module names with no config change
}
ModuleConfigDiff represents what changed between two configs.
func DiffModuleConfigs ¶ added in v0.2.20
func DiffModuleConfigs(old, new *WorkflowConfig) *ModuleConfigDiff
DiffModuleConfigs compares two configs and identifies module-level changes.
type ModuleReconfigurer ¶ added in v0.2.20
type ModuleReconfigurer interface {
// ReconfigureModules applies new configuration to specific running modules.
// Returns the names of any modules that could not be reconfigured in-place
// (requiring a full reload) and any hard error.
ReconfigureModules(ctx context.Context, changes []ModuleConfigChange) (failedModules []string, err error)
}
ModuleReconfigurer is implemented by the engine to support partial (per-module) reloads. When a config change only affects module configs, the engine can apply changes surgically rather than performing a full stop/rebuild/start cycle.
type PipelineConfig ¶
type PipelineConfig struct {
Trigger PipelineTriggerConfig `json:"trigger" yaml:"trigger"`
Steps []PipelineStepConfig `json:"steps" yaml:"steps"`
OnError string `json:"on_error,omitempty" yaml:"on_error,omitempty"`
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Compensation []PipelineStepConfig `json:"compensation,omitempty" yaml:"compensation,omitempty"`
}
PipelineConfig represents a single composable pipeline definition.
type PipelineStepConfig ¶
type PipelineStepConfig struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
Config map[string]any `json:"config,omitempty" yaml:"config,omitempty"`
OnError string `json:"on_error,omitempty" yaml:"on_error,omitempty"`
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}
PipelineStepConfig defines a single step in a pipeline.
type PipelineTriggerConfig ¶
type PipelineTriggerConfig struct {
Type string `json:"type" yaml:"type"`
Config map[string]any `json:"config,omitempty" yaml:"config,omitempty"`
}
PipelineTriggerConfig defines what starts a pipeline.
type PluginRequirement ¶
type PluginRequirement struct {
Name string `json:"name" yaml:"name"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
}
PluginRequirement specifies a required plugin with optional version constraint.
type RequiresConfig ¶
type RequiresConfig struct {
Capabilities []string `json:"capabilities,omitempty" yaml:"capabilities,omitempty"`
Plugins []PluginRequirement `json:"plugins,omitempty" yaml:"plugins,omitempty"`
}
RequiresConfig declares what capabilities and plugins a workflow needs.
type WatcherOption ¶ added in v0.2.20
type WatcherOption func(*ConfigWatcher)
WatcherOption configures a ConfigWatcher.
func WithWatchDebounce ¶ added in v0.2.20
func WithWatchDebounce(d time.Duration) WatcherOption
WithWatchDebounce sets the debounce duration for file change events.
func WithWatchLogger ¶ added in v0.2.20
func WithWatchLogger(l *slog.Logger) WatcherOption
WithWatchLogger sets the logger for the watcher.
type WorkflowConfig ¶
type WorkflowConfig struct {
Modules []ModuleConfig `json:"modules" yaml:"modules"`
Workflows map[string]any `json:"workflows" yaml:"workflows"`
Triggers map[string]any `json:"triggers" yaml:"triggers"`
Pipelines map[string]any `json:"pipelines,omitempty" yaml:"pipelines,omitempty"`
Platform map[string]any `json:"platform,omitempty" yaml:"platform,omitempty"`
Requires *RequiresConfig `json:"requires,omitempty" yaml:"requires,omitempty"`
ConfigDir string `json:"-" yaml:"-"` // directory containing the config file, used for relative path resolution
}
WorkflowConfig represents the overall configuration for the workflow engine
func LoadFromFile ¶
func LoadFromFile(filepath string) (*WorkflowConfig, error)
LoadFromFile loads a workflow configuration from a YAML file
func LoadFromString ¶
func LoadFromString(yamlContent string) (*WorkflowConfig, error)
LoadFromString loads a workflow configuration from a YAML string.
func MergeApplicationConfig ¶ added in v0.1.6
func MergeApplicationConfig(appCfg *ApplicationConfig) (*WorkflowConfig, error)
MergeApplicationConfig loads all workflow config files referenced by an ApplicationConfig and merges them into a single WorkflowConfig. This is useful for callers that need a single combined config (e.g., the server's admin merge step) before passing it to the engine.
Module name conflicts across files are reported as errors.
func NewEmptyWorkflowConfig ¶
func NewEmptyWorkflowConfig() *WorkflowConfig
NewEmptyWorkflowConfig creates a new empty workflow configuration
func (*WorkflowConfig) ResolveRelativePath ¶
func (c *WorkflowConfig) ResolveRelativePath(path string) string
ResolveRelativePath resolves a path relative to the config file's directory. If the path is absolute, it is returned as-is.
type WorkflowRef ¶ added in v0.1.6
type WorkflowRef struct {
// File is the path to the workflow YAML config file (relative to the application config).
File string `json:"file" yaml:"file"`
// Name is an optional override for the workflow's name within the application namespace.
// If empty, the filename stem (without extension) is used.
Name string `json:"name,omitempty" yaml:"name,omitempty"`
}
WorkflowRef is a reference to a workflow config file within an application config.