Documentation
¶
Overview ¶
Package workflow provides the workflow definition loader and runtime.
Index ¶
- func ApplyInputDefaults(declared []types.WorkflowInputDef, input types.KV) types.KV
- func DetermineRuntimeType(t *types.Task) string
- func ExportYAML(wf *types.WorkflowMetadata) ([]byte, error)
- func InputsToMaps(inputs []types.WorkflowInputDef) []map[string]any
- func LoadFile(path string) (*types.WorkflowMetadata, error)
- func MetadataFromRows(rows WorkflowRows) (*types.WorkflowMetadata, error)
- func ParseYAML(data []byte) (*types.WorkflowMetadata, error)
- func ReloadTriggers(ctx context.Context) error
- func RetryToMap(r *types.RetryConfig) map[string]any
- func SetReloadService(svc *Service)
- func ValidateDAG(tasks []types.WorkflowTask) error
- func ValidateInputs(declared []types.WorkflowInputDef, input types.KV) error
- func WorkflowTaskToTask(wt types.WorkflowTask) (*types.Task, error)
- type ActionInfo
- type Catalog
- type CheckpointData
- type DefinitionStore
- type Runner
- func (r *Runner) Close() error
- func (r *Runner) Execute(ctx context.Context, wf types.WorkflowMetadata, input types.KV, file string) error
- func (r *Runner) ResumeWorkflow(ctx context.Context, runID int64) error
- func (r *Runner) Run(ctx context.Context, t *types.Task) error
- func (r *Runner) WithDefinitionStore(ds DefinitionStore) *Runner
- func (r *Runner) WithExistingRun(run *gen.WorkflowRun) *Runner
- func (r *Runner) WithWorkflowID(id int64) *Runner
- type Service
- func (s *Service) ApplyYAML(ctx context.Context, data []byte) (*gen.Workflow, error)
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Export(ctx context.Context, name string) ([]byte, error)
- func (s *Service) Get(ctx context.Context, name string) (*types.WorkflowMetadata, error)
- func (s *Service) List(ctx context.Context) ([]*gen.Workflow, error)
- func (s *Service) ListRuns(ctx context.Context, name string) ([]*gen.WorkflowRun, error)
- func (s *Service) LookupWebhook(path string) (*WebhookEndpoint, bool)
- func (s *Service) ReloadTriggers(ctx context.Context) error
- func (s *Service) StartRunAsync(ctx context.Context, name, triggerType string, input types.KV) (int64, error)
- func (s *Service) Stop()
- func (s *Service) WebhookConfigs() map[string]*WebhookEndpoint
- type WebhookEndpoint
- type WorkflowRows
- type WorkflowRunStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyInputDefaults ¶ added in v0.98.0
ApplyInputDefaults copies input and fills missing keys from declared defaults.
func DetermineRuntimeType ¶
func ExportYAML ¶ added in v0.98.0
func ExportYAML(wf *types.WorkflowMetadata) ([]byte, error)
ExportYAML marshals a workflow definition to YAML exchange format.
func InputsToMaps ¶ added in v0.98.0
func InputsToMaps(inputs []types.WorkflowInputDef) []map[string]any
InputsToMaps converts WorkflowInputDef slice to JSON-friendly maps for storage.
func LoadFile ¶
func LoadFile(path string) (*types.WorkflowMetadata, error)
LoadFile reads and parses a workflow YAML file from disk.
func MetadataFromRows ¶ added in v0.98.0
func MetadataFromRows(rows WorkflowRows) (*types.WorkflowMetadata, error)
MetadataFromRows converts normalized store rows into WorkflowMetadata.
func ParseYAML ¶
func ParseYAML(data []byte) (*types.WorkflowMetadata, error)
ParseYAML unmarshals workflow YAML, validates structure, input types, and input.* template refs.
func ReloadTriggers ¶ added in v0.98.0
ReloadTriggers reloads cron and webhook triggers on the wired Service.
func RetryToMap ¶ added in v0.98.0
func RetryToMap(r *types.RetryConfig) map[string]any
RetryToMap converts RetryConfig to a JSON map for storage.
func SetReloadService ¶ added in v0.98.0
func SetReloadService(svc *Service)
SetReloadService wires the package-level Service used by ReloadTriggers.
func ValidateDAG ¶
func ValidateDAG(tasks []types.WorkflowTask) error
func ValidateInputs ¶ added in v0.98.0
func ValidateInputs(declared []types.WorkflowInputDef, input types.KV) error
ValidateInputs checks required fields and type constraints against declared input defs.
func WorkflowTaskToTask ¶
func WorkflowTaskToTask(wt types.WorkflowTask) (*types.Task, error)
Types ¶
type ActionInfo ¶
type ActionInfo struct {
Type string
Details string
IsCapability bool
CapType string
Operation string
}
func ParseAction ¶
func ParseAction(action string) ActionInfo
type Catalog ¶ added in v0.98.0
type Catalog interface {
DefinitionStore
ApplyDefinition(ctx context.Context, meta *types.WorkflowMetadata) (*gen.Workflow, error)
ListDefinitions(ctx context.Context) ([]*gen.Workflow, error)
DeleteDefinitionByName(ctx context.Context, name string) error
ListRunsByName(ctx context.Context, name string) ([]*gen.WorkflowRun, error)
}
Catalog loads and mutates workflow definitions stored in the database.
type CheckpointData ¶
type CheckpointData struct {
StepIndex int `json:"step_index"`
CompletedTasks map[string]bool `json:"completed_tasks"`
StepResults map[string]string `json:"step_results"`
Input types.KV `json:"input"`
HeartbeatAt time.Time `json:"heartbeat_at"`
}
CheckpointData is the intermediate state saved at each workflow step boundary.
type DefinitionStore ¶ added in v0.98.0
type DefinitionStore interface {
GetMetadata(ctx context.Context, name string) (*types.WorkflowMetadata, error)
}
DefinitionStore loads workflow definitions by name for resume and DB-backed runs.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func NewRunner ¶
func NewRunner() *Runner
NewRunner creates a Runner without persistence. Use NewRunnerWithStore to enable run records.
func NewRunnerWithStore ¶
func NewRunnerWithStore(store WorkflowRunStore, auditor audit.Auditor, wc *metrics.WorkflowCollector, workflowFile, triggerType string) *Runner
NewRunnerWithStore creates a Runner that persists run and step records to the given store. workflowFile and triggerType are recorded in the run for audit; empty workflowFile becomes "db".
func (*Runner) Close ¶
Close releases all executor engine resources (Docker clients, SSH connections, capability runtimes).
func (*Runner) ResumeWorkflow ¶
ResumeWorkflow resumes a previously failed or incomplete workflow run from its checkpoint. Definitions are loaded from DefinitionStore by workflow name (file-based resume is removed).
func (*Runner) WithDefinitionStore ¶ added in v0.98.0
func (r *Runner) WithDefinitionStore(ds DefinitionStore) *Runner
WithDefinitionStore attaches a DefinitionStore used to load definitions by name on resume.
func (*Runner) WithExistingRun ¶ added in v0.98.0
func (r *Runner) WithExistingRun(run *gen.WorkflowRun) *Runner
WithExistingRun skips CreateRun and continues execution against the given run record.
func (*Runner) WithWorkflowID ¶ added in v0.98.0
WithWorkflowID sets the workflow definition ID recorded on new runs (0 if unknown).
type Service ¶ added in v0.98.0
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates DB-backed workflow apply/run and trigger registration.
func ActiveService ¶ added in v0.98.0
func ActiveService() *Service
ActiveService returns the package-level Service, or nil if not wired.
func NewService ¶ added in v0.98.0
func NewService(catalog Catalog, runs WorkflowRunStore, auditor audit.Auditor, wc *metrics.WorkflowCollector) *Service
NewService creates a workflow Service.
func (*Service) ApplyYAML ¶ added in v0.98.0
ApplyYAML parses YAML, upserts the definition, and reloads triggers.
func (*Service) Delete ¶ added in v0.98.0
Delete removes a workflow definition and reloads triggers.
func (*Service) LookupWebhook ¶ added in v0.98.0
func (s *Service) LookupWebhook(path string) (*WebhookEndpoint, bool)
LookupWebhook returns the webhook endpoint for a path (without /webhook/workflow/ prefix).
func (*Service) ReloadTriggers ¶ added in v0.98.0
ReloadTriggers rebuilds cron jobs and webhook configs from enabled workflow definitions.
func (*Service) StartRunAsync ¶ added in v0.98.0
func (s *Service) StartRunAsync(ctx context.Context, name, triggerType string, input types.KV) (int64, error)
StartRunAsync validates inputs, creates a run record, and executes the workflow in a goroutine. It returns the new run ID immediately.
func (*Service) Stop ¶ added in v0.98.0
func (s *Service) Stop()
Stop shuts down the cron scheduler.
func (*Service) WebhookConfigs ¶ added in v0.98.0
func (s *Service) WebhookConfigs() map[string]*WebhookEndpoint
WebhookConfigs returns a copy of the current webhook path map.
type WebhookEndpoint ¶ added in v0.98.0
type WebhookEndpoint struct {
WorkflowName string
Config *pipeline.WebhookConfig
}
WebhookEndpoint describes a registered workflow webhook trigger.
type WorkflowRows ¶ added in v0.98.0
type WorkflowRows struct {
Workflow *gen.Workflow
Tasks []*gen.WorkflowTask
Triggers []*gen.WorkflowTrigger
}
WorkflowRows is the store-level projection used to rebuild WorkflowMetadata.
type WorkflowRunStore ¶
type WorkflowRunStore interface {
CreateRun(ctx context.Context, workflowID int64, workflowName, workflowFile, triggerType string, triggerInfo, inputParams map[string]any) (*gen.WorkflowRun, error)
UpdateRunStatus(ctx context.Context, runID int64, status int, errMsg string) error
CreateStepRun(ctx context.Context, runID int64, stepID, stepName, action, actionType string, params map[string]any, attempt int) (*gen.WorkflowStepRun, error)
UpdateStepRun(ctx context.Context, stepRunID int64, status int, result map[string]any, errMsg string, attempt int) error
SaveCheckpoint(ctx context.Context, runID int64, data any) error
GetIncompleteRuns(ctx context.Context) ([]*gen.WorkflowRun, error)
GetCheckpoint(ctx context.Context, runID int64, target any) error
GetRun(ctx context.Context, runID int64) (*gen.WorkflowRun, error)
UpdateRunHeartbeat(ctx context.Context, runID int64) error
}
WorkflowRunStore persists workflow runs, step runs, and checkpoint data.