Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyHumanTaskConfig(step *models.ExecutionStep, n *models.Node)
- func ExecutionIDFromContext(ctx context.Context) string
- func FindNode(wf *models.Workflow, nodeID string) *models.Node
- func IsInteractiveNode(n models.Node) bool
- func IsPermanent(err error) bool
- func MergeActionPayload(existingInput, action, payload string) string
- func NamespaceFromContext(ctx context.Context) string
- func NewStepForNode(ns, execID, nodeID, input string, n *models.Node) *models.ExecutionStep
- func WithEngine(ctx context.Context, e *Engine) context.Context
- func WithExecutionContext(ctx context.Context, namespace, execID string) context.Context
- type Engine
- func (e *Engine) Advance(ctx context.Context, namespace, execID, nodeID, action, payload string) (string, []*models.ExecutionStep, error)
- func (e *Engine) CancelExecution(ctx context.Context, namespace string, execID string) error
- func (e *Engine) CheckAccess(ctx context.Context, resource, action string) error
- func (e *Engine) ClaimTask(ctx context.Context, namespace, execID, nodeID, actor string) error
- func (e *Engine) CompleteStep(ctx context.Context, step *models.ExecutionStep, output string) error
- func (e *Engine) CompleteTask(ctx context.Context, namespace, execID, nodeID, actor, action, payload string) (string, []*models.ExecutionStep, error)
- func (e *Engine) EventBus() *EventBus
- func (e *Engine) Execute(ctx context.Context, namespace, workflowID string, input []byte) (string, error)
- func (e *Engine) ExecutionSnapshot(ctx context.Context, namespace, execID string) (*models.Execution, *models.Workflow, []*models.ExecutionStep, error)
- func (e *Engine) FailExecution(ctx context.Context, namespace string, execID string, message string) error
- func (e *Engine) GetExecutionStatus(ctx context.Context, namespace string, execID string) (*models.Execution, error)
- func (e *Engine) GetExecutionSteps(ctx context.Context, namespace string, execID string) ([]*models.ExecutionStep, error)
- func (e *Engine) GetLogger() *slog.Logger
- func (e *Engine) GetVar(ctx context.Context, namespace, execID, key string) (interface{}, error)
- func (e *Engine) GetVars(ctx context.Context, namespace, execID string) (map[string]interface{}, error)
- func (e *Engine) ListCompensationJournal(ctx context.Context, namespace, execID string) ([]*models.CompensationRecord, error)
- func (e *Engine) ListExecutions(ctx context.Context, namespace string) ([]*models.Execution, error)
- func (e *Engine) ListTasks(ctx context.Context, namespace string, filter TaskFilter) ([]*models.ExecutionStep, error)
- func (e *Engine) MergeVars(ctx context.Context, namespace, execID string, vars map[string]interface{}) error
- func (e *Engine) NodeRegistry() *Registry
- func (e *Engine) ReapTimeouts(ctx context.Context, namespace string) error
- func (e *Engine) RegisterWorkflow(ctx context.Context, namespace string, wf *models.Workflow) error
- func (e *Engine) ReleaseTask(ctx context.Context, namespace, execID, nodeID, actor string) error
- func (e *Engine) RollbackTo(ctx context.Context, namespace, execID, nodeID, reason, actor string) error
- func (e *Engine) SetAuthProvider(provider auth.AuthProvider) *Engine
- func (e *Engine) SetEventBus(bus *EventBus) *Engine
- func (e *Engine) SetHostHooks(h HostHooks) *Engine
- func (e *Engine) SetVar(ctx context.Context, namespace, execID, key string, value interface{}) error
- func (e *Engine) SetWorkflowStatus(ctx context.Context, namespace, workflowID string, ...) error
- func (e *Engine) SignalExecution(ctx context.Context, namespace string, execID string, nodeID string, ...) error
- func (e *Engine) StartWorker(ctx context.Context, namespace, workerID string)
- func (e *Engine) StartWorkerWithOptions(ctx context.Context, namespace, workerID string, opts WorkerOptions)
- func (e *Engine) StartWorkflow(ctx context.Context, namespace, workflowID string, input string) (string, error)
- func (e *Engine) SweepStuckExecutions(ctx context.Context, namespace string, olderThan time.Duration) (int, error)
- func (e *Engine) WithLogger(l *slog.Logger) *Engine
- func (e *Engine) WorkflowDefinition(ctx context.Context, namespace, id string) (*models.Workflow, error)
- func (e *Engine) WorkflowDefinitions(ctx context.Context, namespace string) ([]*models.Workflow, error)
- type Event
- type EventBus
- type EventHandler
- type EventType
- type Graph
- type HostHooks
- type InputBuilder
- type NodeExecutor
- type PermanentError
- type PortInput
- type Registry
- func (r *Registry) Get(nodeType string) (NodeExecutor, error)
- func (r *Registry) GetFunction(name string) (func(context.Context, map[string]interface{}) (map[string]interface{}, error), ...)
- func (r *Registry) ListFunctions() []string
- func (r *Registry) Register(nodeType string, executor NodeExecutor)
- func (r *Registry) RegisterFunction(name string, ...)
- type TaskFilter
- type Telemetry
- func (t *Telemetry) IncFailed()
- func (t *Telemetry) IncProcessed(namespace, nodeType string, status string)
- func (t *Telemetry) IncProcessedLegacy()
- func (t *Telemetry) IncRetried()
- func (t *Telemetry) ObserveDuration(namespace, nodeType string, duration time.Duration)
- func (t *Telemetry) WorkerStarted(id string)
- func (t *Telemetry) WorkerStartedLegacy()
- func (t *Telemetry) WorkerStopped(id string)
- func (t *Telemetry) WorkerStoppedLegacy()
- type WaitUntilError
- type Worker
- type WorkerOptions
Constants ¶
const ( NodeTypeHumanTask = "humantask" WaitHuman = "HUMAN_WAIT" WaitSignal = "SIGNAL_WAIT" )
const PortsKey = "__ports"
PortsKey is the output envelope key used by port-aware executors: {"__ports": {"0": <data>, "1": <data>}}. A port that is absent carries no data, so edges leaving it are dead and their targets may be skipped.
Variables ¶
var ErrStepConflict = errors.New("step was changed concurrently")
ErrStepConflict is returned when a step changed concurrently (e.g. a waiting step was already resumed, or a reclaimed step is now owned by another worker) and the transition was not applied.
Functions ¶
func ApplyHumanTaskConfig ¶
func ApplyHumanTaskConfig(step *models.ExecutionStep, n *models.Node)
ApplyHumanTaskConfig copies assignee/claim fields from node config onto a step.
func ExecutionIDFromContext ¶
func IsInteractiveNode ¶
IsInteractiveNode returns true when the node should not be auto-claimed by workers (humantask or execution_mode=interactive).
func IsPermanent ¶
IsPermanent reports whether err (or anything it wraps) is permanent.
func MergeActionPayload ¶
MergeActionPayload merges action + payload JSON into an output map.
func NamespaceFromContext ¶
func NewStepForNode ¶
func NewStepForNode(ns, execID, nodeID, input string, n *models.Node) *models.ExecutionStep
NewStepForNode creates a PENDING or WAITING step based on node type/mode.
func WithEngine ¶
WithEngine attaches the engine pointer for setvariable durable writes.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func EngineFromContext ¶
func (*Engine) Advance ¶
func (e *Engine) Advance(ctx context.Context, namespace, execID, nodeID, action, payload string) (string, []*models.ExecutionStep, error)
Advance completes a WAITING (or PENDING interactive) step synchronously. action is a free-form string (approve/reject/submit); payload is JSON.
func (*Engine) CancelExecution ¶
func (*Engine) CheckAccess ¶
CheckAccess runs the configured AuthProvider (no-op when unset).
func (*Engine) CompleteStep ¶
CompleteStep handles the transition after a node finishes. The step must still be in the state the caller read (WAITING, or RUNNING and owned by the same worker); otherwise ErrStepConflict is returned and nothing changes. Scheduling continues even if ctx is cancelled after the step was persisted, so children are never orphaned by a disconnected caller.
func (*Engine) CompleteTask ¶
func (e *Engine) CompleteTask(ctx context.Context, namespace, execID, nodeID, actor, action, payload string) (string, []*models.ExecutionStep, error)
CompleteTask claims (if needed) and advances a human task.
func (*Engine) Execute ¶
func (e *Engine) Execute(ctx context.Context, namespace, workflowID string, input []byte) (string, error)
Execute is an alias for StartWorkflow (accepts []byte input)
func (*Engine) ExecutionSnapshot ¶
func (e *Engine) ExecutionSnapshot(ctx context.Context, namespace, execID string) (*models.Execution, *models.Workflow, []*models.ExecutionStep, error)
ExecutionSnapshot returns an execution with its workflow and steps, without auth checks. It is meant for executors running inside that execution (e.g. expression engines resolving other nodes' outputs).
func (*Engine) FailExecution ¶
func (*Engine) GetExecutionStatus ¶
func (*Engine) GetExecutionSteps ¶
func (*Engine) GetVars ¶
func (e *Engine) GetVars(ctx context.Context, namespace, execID string) (map[string]interface{}, error)
GetVars returns all durable variables.
func (*Engine) ListCompensationJournal ¶
func (e *Engine) ListCompensationJournal(ctx context.Context, namespace, execID string) ([]*models.CompensationRecord, error)
ListCompensationJournal returns compensation/rollback records for an execution.
func (*Engine) ListExecutions ¶
ListExecutions returns all executions in a namespace.
func (*Engine) ListTasks ¶
func (e *Engine) ListTasks(ctx context.Context, namespace string, filter TaskFilter) ([]*models.ExecutionStep, error)
ListTasks returns WAITING human/interactive steps.
func (*Engine) MergeVars ¶
func (e *Engine) MergeVars(ctx context.Context, namespace, execID string, vars map[string]interface{}) error
MergeVars merges a map into durable execution variables.
func (*Engine) NodeRegistry ¶
NodeRegistry returns the executor registry used by this engine.
func (*Engine) ReapTimeouts ¶
ReapTimeouts checks for WAITING steps that have passed their timeout period.
func (*Engine) RegisterWorkflow ¶
RegisterWorkflow saves a workflow definition to storage
func (*Engine) ReleaseTask ¶
ReleaseTask clears the claim on a waiting task.
func (*Engine) RollbackTo ¶
func (e *Engine) RollbackTo(ctx context.Context, namespace, execID, nodeID, reason, actor string) error
RollbackTo records a journal entry and enqueues compensation for the target node's CompensateNodeID (or the node itself if it is a compensate node).
func (*Engine) SetAuthProvider ¶
func (e *Engine) SetAuthProvider(provider auth.AuthProvider) *Engine
SetAuthProvider sets the auth provider for authorization checks If not set, all operations are allowed (no auth)
func (*Engine) SetEventBus ¶
SetEventBus replaces the engine event bus (async handlers).
func (*Engine) SetHostHooks ¶
SetHostHooks sets a synchronous host integration handler (WS, notifications).
func (*Engine) SetVar ¶
func (e *Engine) SetVar(ctx context.Context, namespace, execID, key string, value interface{}) error
SetVar sets a durable execution variable.
func (*Engine) SetWorkflowStatus ¶
func (e *Engine) SetWorkflowStatus(ctx context.Context, namespace, workflowID string, status models.WorkflowStatus) error
SetWorkflowStatus marks a workflow definition ACTIVE or INACTIVE without auth checks (for trigger hosts such as the n8n handler).
func (*Engine) SignalExecution ¶
func (*Engine) StartWorker ¶
StartWorker starts a worker loop that processes tasks (one at a time). It blocks until ctx is cancelled and in-flight work has been released.
func (*Engine) StartWorkerWithOptions ¶
func (e *Engine) StartWorkerWithOptions(ctx context.Context, namespace, workerID string, opts WorkerOptions)
StartWorkerWithOptions starts a worker with custom concurrency/polling.
func (*Engine) StartWorkflow ¶
func (e *Engine) StartWorkflow(ctx context.Context, namespace, workflowID string, input string) (string, error)
StartWorkflow creates a new execution for a workflow
func (*Engine) SweepStuckExecutions ¶
func (e *Engine) SweepStuckExecutions(ctx context.Context, namespace string, olderThan time.Duration) (int, error)
SweepStuckExecutions finishes RUNNING executions whose steps have all settled but that were never finalized (e.g. a process crashed between completing a step and scheduling its children). It returns how many executions changed state. Workers call it periodically.
type Event ¶
type Event struct {
Type EventType
Namespace string
Execution *models.Execution
Step *models.ExecutionStep
Workflow *models.Workflow
Metadata map[string]interface{}
}
Event represents a workflow event
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus manages event handlers
func NewEventBus ¶
func NewEventBus() *EventBus
func (*EventBus) RegisterGlobalHandler ¶
func (eb *EventBus) RegisterGlobalHandler(handler EventHandler)
RegisterGlobalHandler adds a handler for ALL known event types.
func (*EventBus) RegisterHandler ¶
func (eb *EventBus) RegisterHandler(eventType EventType, handler EventHandler)
RegisterHandler adds an event handler for specific event type
type EventHandler ¶
EventHandler is the interface for handling workflow events
type EventType ¶
type EventType string
EventType represents different workflow events
const ( EventTypeWorkflowStarted EventType = "workflow.started" EventTypeWorkflowCompleted EventType = "workflow.completed" EventTypeWorkflowFailed EventType = "workflow.failed" EventTypeWorkflowCancelled EventType = "workflow.cancelled" EventTypeStepStarted EventType = "step.started" EventTypeStepCompleted EventType = "step.completed" EventTypeStepFailed EventType = "step.failed" EventTypeStepRetrying EventType = "step.retrying" EventTypeStepWaitingSignal EventType = "step.waiting_signal" EventTypeStepWaitingHuman EventType = "step.waiting_human" EventTypeSignalReceived EventType = "signal.received" EventTypeTaskClaimed EventType = "task.claimed" EventTypeTaskCompleted EventType = "task.completed" EventTypeCompensationTriggered EventType = "compensation.triggered" EventTypeRollbackStarted EventType = "rollback.started" EventTypeScheduleCreated EventType = "schedule.created" EventTypeScheduleUpdated EventType = "schedule.updated" EventTypeSchedulePaused EventType = "schedule.paused" EventTypeScheduleResumed EventType = "schedule.resumed" EventTypeScheduleDeleted EventType = "schedule.deleted" EventTypeScheduleFired EventType = "schedule.fired" EventTypeScheduleFireFailed EventType = "schedule.fire_failed" )
func AllEventTypes ¶
func AllEventTypes() []EventType
AllEventTypes lists every known event type (for global handlers).
type Graph ¶
type Graph struct {
Nodes map[string]models.Node
Edges map[string][]models.Edge // source -> outgoing edges
InDegree map[string]int // target -> number of incoming edges
Predecessors map[string][]string // target -> list of parent node IDs
}
Graph represents the structure of the workflow
func (*Graph) GetInitialNodes ¶
GetInitialNodes returns nodes with no predecessors
func (*Graph) GetNextNodes ¶
GetNextNodes returns direct children of the given node (standard routing)
func (*Graph) GetNextNodesWithBranch ¶
GetNextNodesWithBranch returns children based on output branch (intelligent routing)
type HostHooks ¶
type HostHooks = EventHandler
HostHooks is an alias for sync host integration (WS, notifications).
type InputBuilder ¶
InputBuilder is implemented by executors that need per-edge input (e.g. n8n Merge with two inputs). When implemented, the engine passes every active incoming edge instead of its default aggregation, and does not merge execution variables into the input.
type NodeExecutor ¶
type NodeExecutor interface {
Execute(ctx context.Context, config map[string]interface{}, input string) (string, error)
Validate(config map[string]interface{}) error
}
NodeExecutor defines the interface for a node's logic
type PermanentError ¶
PermanentError can be implemented by executor errors that must not be retried (e.g. a blocked destination or invalid input). The step fails immediately instead of going through the retry policy.
type PortInput ¶
type PortInput struct {
FromNode string `json:"fromNode"`
FromPort string `json:"fromPort"`
ToPort int `json:"toPort"`
Data json.RawMessage `json:"data"`
}
PortInput is the data delivered to a node over one active incoming edge.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the map of available node executors and functions
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) GetFunction ¶
func (r *Registry) GetFunction(name string) (func(context.Context, map[string]interface{}) (map[string]interface{}, error), bool)
GetFunction retrieves a registered function by name
func (*Registry) ListFunctions ¶
ListFunctions returns all registered function names
func (*Registry) Register ¶
func (r *Registry) Register(nodeType string, executor NodeExecutor)
type TaskFilter ¶
type TaskFilter = storage.TaskFilter
TaskFilter is re-exported conceptually via storage; engine uses storage.TaskFilter.
type Telemetry ¶
type Telemetry struct{}
Telemetry bridge to Prometheus
func GetTelemetry ¶
func GetTelemetry() *Telemetry
func (*Telemetry) IncFailed ¶
func (t *Telemetry) IncFailed()
Keep legacy methods for basic worker support (mapped to default labels)
func (*Telemetry) IncProcessed ¶
func (*Telemetry) IncProcessedLegacy ¶
func (t *Telemetry) IncProcessedLegacy()
func (*Telemetry) IncRetried ¶
func (t *Telemetry) IncRetried()
func (*Telemetry) ObserveDuration ¶
func (*Telemetry) WorkerStarted ¶
func (*Telemetry) WorkerStartedLegacy ¶
func (t *Telemetry) WorkerStartedLegacy()
func (*Telemetry) WorkerStopped ¶
func (*Telemetry) WorkerStoppedLegacy ¶
func (t *Telemetry) WorkerStoppedLegacy()
type WaitUntilError ¶
WaitUntilError is returned by an executor that wants to pause until a point in time without blocking a worker: the step is stored as WAITING with Output already computed, and the timeout reaper completes it once At has passed (durable across restarts).
func (*WaitUntilError) Error ¶
func (w *WaitUntilError) Error() string
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
func (*Worker) SetConcurrency ¶
SetConcurrency sets how many steps the worker runs in parallel (min 1).
func (*Worker) SetNamespace ¶
SetNamespace pins the worker to a specific namespace
type WorkerOptions ¶
type WorkerOptions struct {
// Concurrency is the number of steps processed in parallel (default 1).
Concurrency int
// PollInterval is how long an idle worker waits before polling storage
// again (default 100ms). A busy worker claims the next step immediately.
PollInterval time.Duration
}
WorkerOptions tunes a worker.