Documentation
¶
Overview ¶
Package flow provides a high-performance workflow orchestration engine for Go.
Quick Start with MySQL:
import (
"github.com/dgmos/flow"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
func main() {
// Connect to MySQL
db, _ := sqlx.Connect("mysql", "user:pass@tcp(localhost:3306)/db?parseTime=true")
// Create storage (auto-creates tables!)
storage, _ := flow.NewMySQLStorage(db)
// Create engine
registry := flow.NewRegistry()
engine := flow.NewEngine(storage, registry)
// Register your functions
registry.RegisterFunction("MyTask", func(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error) {
return map[string]interface{}{"status": "done"}, nil
})
// Start worker
go engine.StartWorker(ctx, "default", "worker-1")
// Execute workflow
execID, _ := engine.Execute(ctx, "default", "my-workflow", `{"key":"value"}`)
}
Index ¶
- Constants
- Variables
- func ImportN8NWorkflow(data []byte, opts N8NImportOptions) (*Workflow, *N8NReport, error)
- func MetricsRegistry() prometheus.Registerer
- func N8NNodeSupported(nodeType string) bool
- func ToMermaid(wf *Workflow) string
- type APIManager
- type AuthProvider
- type CompensationRecord
- type CronManager
- func (c *CronManager) AddSchedule(ctx context.Context, namespace, workflowID, cronExpr, input string) (string, error)
- func (c *CronManager) AddScheduleWithOpts(ctx context.Context, namespace, workflowID, cronExpr, input string, ...) (string, error)
- func (c *CronManager) GetSchedule(ctx context.Context, namespace, scheduleID string) (*Schedule, error)
- func (c *CronManager) ListSchedules(ctx context.Context, namespace string) ([]*Schedule, error)
- func (c *CronManager) ListSchedulesFiltered(ctx context.Context, namespace string, filter ScheduleListFilter) ([]*Schedule, error)
- func (c *CronManager) PauseSchedule(ctx context.Context, namespace, scheduleID string) error
- func (c *CronManager) PreviewNextRuns(cronExpr, timezone string, n int) ([]time.Time, error)
- func (c *CronManager) RemoveSchedule(ctx context.Context, namespace, scheduleID string) error
- func (c *CronManager) ResumeSchedule(ctx context.Context, namespace, scheduleID string) error
- func (c *CronManager) SetAuthProvider(provider AuthProvider)
- func (c *CronManager) SetEventBus(bus *EventBus)
- func (c *CronManager) SetHostHooks(h EventHandler)
- func (c *CronManager) Start(ctx context.Context) error
- func (c *CronManager) Stop()
- func (c *CronManager) UpdateSchedule(ctx context.Context, namespace, scheduleID string, patch ScheduleUpdateOpts) error
- type Crypto
- type Edge
- type Engine
- func (e *Engine) Advance(ctx context.Context, namespace, execID, nodeID, action, payload string) (string, []*ExecutionStep, error)
- func (e *Engine) CancelExecution(ctx context.Context, namespace, 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) CompleteTask(ctx context.Context, namespace, execID, nodeID, actor, action, payload string) (string, []*ExecutionStep, error)
- func (e *Engine) EnableN8N(opts N8NOptions) *Engine
- func (e *Engine) Execute(ctx context.Context, namespace, workflowID string, input []byte) (string, error)
- func (e *Engine) FailExecution(ctx context.Context, namespace, execID, message string) error
- func (e *Engine) GetExecution(ctx context.Context, namespace, execID string) (*Execution, error)
- func (e *Engine) GetExecutionStatus(ctx context.Context, namespace, execID string) (*Execution, error)
- func (e *Engine) GetExecutionSteps(ctx context.Context, namespace, execID string) ([]*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) InstallN8NWorkflow(ctx context.Context, namespace string, data []byte, opts N8NInstallOptions) (*N8NInstallResult, error)
- func (e *Engine) ListCompensationJournal(ctx context.Context, namespace, execID string) ([]*CompensationRecord, error)
- func (e *Engine) ListExecutions(ctx context.Context, namespace string) ([]*Execution, error)
- func (e *Engine) ListTasks(ctx context.Context, namespace string, filter TaskFilter) ([]*ExecutionStep, error)
- func (e *Engine) MergeVars(ctx context.Context, namespace, execID string, vars map[string]interface{}) error
- func (e *Engine) N8NHandler(opts N8NHandlerOptions) http.Handler
- func (e *Engine) ReapTimeouts(ctx context.Context, namespace string) error
- func (e *Engine) RegisterWorkflow(ctx context.Context, namespace string, wf *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 AuthProvider) *Engine
- func (e *Engine) SetEventBus(bus *EventBus) *Engine
- func (e *Engine) SetHostHooks(h EventHandler) *Engine
- func (e *Engine) SetOutboundPolicy(p OutboundPolicy) *Engine
- func (e *Engine) SetVar(ctx context.Context, namespace, execID, key string, value interface{}) error
- func (e *Engine) SignalExecution(ctx context.Context, namespace, execID, nodeID, output 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) WithLogger(l *slog.Logger) *Engine
- type Event
- type EventBus
- type EventHandler
- type EventType
- type Execution
- type ExecutionStep
- type Graph
- type HandlerFunc
- type HostHooks
- type LegacyStep
- type N8NChatMemoryReplacer
- type N8NChatMemoryStore
- type N8NChatMessage
- type N8NCredentialProvider
- type N8NCredentialRef
- type N8NHandlerOptions
- type N8NImportOptions
- type N8NInstallOptions
- type N8NInstallResult
- type N8NIssue
- type N8NItem
- type N8NOptions
- type N8NPollStateStore
- type N8NPollStateSwapper
- type N8NReport
- type N8NStaticCredentials
- type N8NTrigger
- type Node
- type NodeBuilder
- func (nb *NodeBuilder) If(targetID, condition string) *NodeBuilder
- func (nb *NodeBuilder) Then(targetID string) *NodeBuilder
- func (nb *NodeBuilder) WithConfig(key string, value interface{}) *NodeBuilder
- func (nb *NodeBuilder) WithRetry(count int) *NodeBuilder
- func (nb *NodeBuilder) WithSaga(compensateNodeID string) *NodeBuilder
- type NodeExecutor
- type OutboundPolicy
- type PermanentError
- type Registry
- type RetryPolicy
- type SQLStorageOptions
- type Schedule
- type ScheduleListFilter
- type ScheduleOpts
- type ScheduleUpdateOpts
- type Storage
- func NewMemoryStorage() Storage
- func NewMySQLStorage(db *sqlx.DB) (Storage, error)
- func NewMySQLStorageWithOptions(db *sqlx.DB, opts SQLStorageOptions) (Storage, error)
- func NewPostgreSQLStorage(db *sqlx.DB) (Storage, error)
- func NewPostgreSQLStorageWithOptions(db *sqlx.DB, opts SQLStorageOptions) (Storage, error)
- func NewRedisStorage(addr string, password string, db int) Storage
- func NewSQLStorageFromDB(db *sql.DB, dialect string, opts SQLStorageOptions) (Storage, error)
- type TaskFilter
- type TaskStatus
- type WebhookManager
- type Worker
- type WorkerOptions
- type Workflow
- type WorkflowBuilder
- func (b *WorkflowBuilder) AddNode(id, nodeType string) *NodeBuilder
- func (b *WorkflowBuilder) Build() *Workflow
- func (b *WorkflowBuilder) Connect(sourceID, targetID string) *WorkflowBuilder
- func (b *WorkflowBuilder) ConnectIf(sourceID, targetID, condition string) *WorkflowBuilder
- func (b *WorkflowBuilder) Visualize() string
- type WorkflowStatus
Constants ¶
const ( NodeTypeFunction = "function" NodeTypeHTTP = "http" NodeTypeCondition = "condition" NodeTypeLog = "log" NodeTypeTransform = "transform" NodeTypeSignal = "signal" NodeTypeSubWorkflow = "subworkflow" NodeTypeAI = "ai" NodeTypeNotify = "notify" NodeTypeSwitch = "switch" NodeTypeWait = "wait" NodeTypeSetVariable = "setvariable" NodeTypeHumanTask = "humantask" )
Node types (use these strings in Node.Type field)
const ( WorkflowActive = models.WorkflowActive WorkflowInactive = models.WorkflowInactive )
Workflow statuses
const ( StatusPending = models.TaskPending StatusRunning = models.TaskRunning StatusCompleted = models.TaskCompleted StatusFailed = models.TaskFailed StatusSkipped = models.TaskSkipped StatusWaiting = models.TaskWaiting StatusCancelled = models.TaskCancelled )
Task/Execution statuses
const ( ClaimAny = models.ClaimAny ClaimAll = models.ClaimAll ClaimFirst = models.ClaimFirst )
Claim mode constants
const ( EventWorkflowStarted = engine.EventTypeWorkflowStarted EventWorkflowCompleted = engine.EventTypeWorkflowCompleted EventWorkflowFailed = engine.EventTypeWorkflowFailed EventWorkflowCancelled = engine.EventTypeWorkflowCancelled EventStepStarted = engine.EventTypeStepStarted EventStepCompleted = engine.EventTypeStepCompleted EventStepFailed = engine.EventTypeStepFailed EventStepRetrying = engine.EventTypeStepRetrying EventStepWaitingSignal = engine.EventTypeStepWaitingSignal EventStepWaitingHuman = engine.EventTypeStepWaitingHuman EventSignalReceived = engine.EventTypeSignalReceived EventTaskClaimed = engine.EventTypeTaskClaimed EventTaskCompleted = engine.EventTypeTaskCompleted EventCompensationTriggered = engine.EventTypeCompensationTriggered EventRollbackStarted = engine.EventTypeRollbackStarted EventScheduleCreated = engine.EventTypeScheduleCreated EventScheduleUpdated = engine.EventTypeScheduleUpdated EventSchedulePaused = engine.EventTypeSchedulePaused EventScheduleResumed = engine.EventTypeScheduleResumed EventScheduleDeleted = engine.EventTypeScheduleDeleted EventScheduleFired = engine.EventTypeScheduleFired EventScheduleFireFailed = engine.EventTypeScheduleFireFailed )
Event types
const N8NTriggerKey = n8n.TriggerKey
N8NTriggerKey selects the trigger that starts an execution of an imported workflow: Execute(ctx, ns, id, []byte(`{"__trigger": "Schedule Trigger"}`)). Without it the workflow's default trigger runs.
Variables ¶
var ( ErrDestinationBlocked = node.ErrDestinationBlocked ErrResponseTooLarge = node.ErrResponseTooLarge )
Errors returned by http/notify nodes when the OutboundPolicy is violated. They are permanent: the step fails without retries.
var ( WorkflowsStarted = telemetry.WorkflowsStarted WorkflowsCompleted = telemetry.WorkflowsCompleted WorkflowsFailed = telemetry.WorkflowsFailed StepsProcessed = telemetry.StepsProcessed StepDuration = telemetry.StepDuration ActiveWorkers = telemetry.ActiveWorkers SchedulesActive = telemetry.SchedulesActive ScheduleFires = telemetry.ScheduleFires )
Prometheus metrics (pre-registered)
var ErrN8NNotRunnable = errors.New("n8n workflow uses unsupported features")
ErrN8NNotRunnable is returned by InstallN8NWorkflow when the workflow uses unsupported features and AllowPartial is false.
var ErrN8NWebhookConflict = errors.New("webhook path is already used by another workflow")
ErrN8NWebhookConflict is returned when another workflow already serves a webhook path the imported workflow wants.
Functions ¶
func ImportN8NWorkflow ¶
func ImportN8NWorkflow(data []byte, opts N8NImportOptions) (*Workflow, *N8NReport, error)
ImportN8NWorkflow converts an n8n workflow export (or a template from the n8n template API) into a Workflow and reports unsupported nodes, required credentials and triggers. It does not register the workflow.
func MetricsRegistry ¶
func MetricsRegistry() prometheus.Registerer
MetricsRegistry returns the default Prometheus registerer.
func N8NNodeSupported ¶
N8NNodeSupported reports whether an n8n node type is implemented.
Types ¶
type APIManager ¶
type APIManager struct {
*trigger.APIManager
}
APIManager provides REST API for workflow management
func NewAPIManager ¶
func NewAPIManager(webhookMgr *WebhookManager) *APIManager
NewAPIManager creates a REST API handler.
Example:
apiMgr := flow.NewAPIManager(webhookMgr).WithCron(engine.CronManager)
http.Handle("/", apiMgr)
Endpoints:
- GET /health
- GET /metrics (Prometheus)
- GET /api/{namespace}/executions
- GET /api/{namespace}/executions/{id}
- GET /api/{namespace}/executions/{id}/steps
- POST /api/{namespace}/executions/{id}/cancel
- POST /api/{namespace}/executions/{id}/signal/{nodeID}
- POST /api/{namespace}/executions/{id}/rollback
- POST /api/{namespace}/executions/{id}/tasks/{nodeId}/claim|release|complete|advance
- GET /api/{namespace}/tasks
- GET|POST /api/{namespace}/schedules
- GET|PUT|DELETE /api/{namespace}/schedules/{id}
- POST /api/{namespace}/schedules/{id}/pause|resume
- POST /api/{namespace}/schedules/preview
func (*APIManager) ServeHTTP ¶
func (a *APIManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles API requests
func (*APIManager) WithCron ¶
func (a *APIManager) WithCron(c *CronManager) *APIManager
WithCron enables schedule management REST endpoints.
type AuthProvider ¶
type AuthProvider = auth.AuthProvider
AuthProvider is the pluggable authorization interface.
type CompensationRecord ¶
type CompensationRecord = models.CompensationRecord
CompensationRecord audits saga/rollback activity.
type CronManager ¶
type CronManager struct {
*trigger.CronManager
}
CronManager manages scheduled workflow execution
func NewCronManager ¶
func NewCronManager(eng *Engine, store Storage, logger *slog.Logger) *CronManager
NewCronManager creates a durable cron scheduler backed by storage.
Example:
cronMgr := flow.NewCronManager(engine, storage, logger)
_ = cronMgr.Start(ctx)
id, _ := cronMgr.AddSchedule(ctx, "default", "backup-workflow", "0 0 2 * * *", `{"type":"daily"}`)
func (*CronManager) AddSchedule ¶
func (c *CronManager) AddSchedule(ctx context.Context, namespace, workflowID, cronExpr, input string) (string, error)
AddSchedule persists and registers a cron trigger; returns durable schedule ID.
func (*CronManager) AddScheduleWithOpts ¶
func (c *CronManager) AddScheduleWithOpts(ctx context.Context, namespace, workflowID, cronExpr, input string, opts ScheduleOpts) (string, error)
AddScheduleWithOpts is AddSchedule with CatchUp and related options.
func (*CronManager) GetSchedule ¶
func (c *CronManager) GetSchedule(ctx context.Context, namespace, scheduleID string) (*Schedule, error)
GetSchedule returns a durable schedule definition.
func (*CronManager) ListSchedules ¶
ListSchedules lists schedules for a tenant namespace.
func (*CronManager) ListSchedulesFiltered ¶
func (c *CronManager) ListSchedulesFiltered(ctx context.Context, namespace string, filter ScheduleListFilter) ([]*Schedule, error)
ListSchedulesFiltered lists schedules with optional filters.
func (*CronManager) PauseSchedule ¶
func (c *CronManager) PauseSchedule(ctx context.Context, namespace, scheduleID string) error
PauseSchedule soft-disables a schedule without deleting it.
func (*CronManager) PreviewNextRuns ¶
PreviewNextRuns returns upcoming fire times for a cron expression (UI helper).
func (*CronManager) RemoveSchedule ¶
func (c *CronManager) RemoveSchedule(ctx context.Context, namespace, scheduleID string) error
RemoveSchedule deletes a schedule from storage and unregisters it from memory.
func (*CronManager) ResumeSchedule ¶
func (c *CronManager) ResumeSchedule(ctx context.Context, namespace, scheduleID string) error
ResumeSchedule reactivates a paused schedule.
func (*CronManager) SetAuthProvider ¶
func (c *CronManager) SetAuthProvider(provider AuthProvider)
SetAuthProvider sets authorization checks for schedule operations.
func (*CronManager) SetEventBus ¶
func (c *CronManager) SetEventBus(bus *EventBus)
SetEventBus wires schedule.* lifecycle events.
func (*CronManager) SetHostHooks ¶
func (c *CronManager) SetHostHooks(h EventHandler)
SetHostHooks wires sync host integration for schedule events.
func (*CronManager) Start ¶
func (c *CronManager) Start(ctx context.Context) error
Start loads active schedules from storage and begins the cron runner.
func (*CronManager) UpdateSchedule ¶
func (c *CronManager) UpdateSchedule(ctx context.Context, namespace, scheduleID string, patch ScheduleUpdateOpts) error
UpdateSchedule applies a partial patch to an existing schedule.
type Engine ¶
type Engine struct {
*engine.Engine
CronManager *CronManager
// contains filtered or unexported fields
}
Engine is the workflow execution engine
func (*Engine) Advance ¶
func (e *Engine) Advance(ctx context.Context, namespace, execID, nodeID, action, payload string) (string, []*ExecutionStep, error)
Advance interactively completes a waiting/interactive step.
func (*Engine) CancelExecution ¶
CancelExecution cancels a running execution
func (*Engine) CheckAccess ¶
CheckAccess runs the configured AuthProvider (no-op when unset).
func (*Engine) CompleteTask ¶
func (e *Engine) CompleteTask(ctx context.Context, namespace, execID, nodeID, actor, action, payload string) (string, []*ExecutionStep, error)
CompleteTask claims (if needed) and completes a human task.
func (*Engine) EnableN8N ¶
func (e *Engine) EnableN8N(opts N8NOptions) *Engine
EnableN8N registers the n8n node types with this engine. Call it once, before registering or running imported workflows.
func (*Engine) Execute ¶
func (e *Engine) Execute(ctx context.Context, namespace, workflowID string, input []byte) (string, error)
Execute starts a new workflow execution (alias for StartWorkflow)
func (*Engine) FailExecution ¶
FailExecution marks an execution as failed
func (*Engine) GetExecution ¶
GetExecution retrieves an execution by ID
func (*Engine) GetExecutionStatus ¶
func (e *Engine) GetExecutionStatus(ctx context.Context, namespace, execID string) (*Execution, error)
GetExecutionStatus retrieves an execution's status
func (*Engine) GetExecutionSteps ¶
func (e *Engine) GetExecutionSteps(ctx context.Context, namespace, execID string) ([]*ExecutionStep, error)
GetExecutionSteps retrieves all steps for an execution
func (*Engine) GetVars ¶
func (e *Engine) GetVars(ctx context.Context, namespace, execID string) (map[string]interface{}, error)
GetVars returns all durable execution variables.
func (*Engine) InstallN8NWorkflow ¶
func (e *Engine) InstallN8NWorkflow(ctx context.Context, namespace string, data []byte, opts N8NInstallOptions) (*N8NInstallResult, error)
InstallN8NWorkflow imports, registers and activates an n8n workflow: schedule triggers become durable schedules (requires the CronManager to be started), webhook/chat/form triggers are served by N8NHandler.
func (*Engine) ListCompensationJournal ¶
func (e *Engine) ListCompensationJournal(ctx context.Context, namespace, execID string) ([]*CompensationRecord, error)
ListCompensationJournal lists compensation/rollback records.
func (*Engine) ListExecutions ¶
ListExecutions lists all executions in a namespace.
func (*Engine) ListTasks ¶
func (e *Engine) ListTasks(ctx context.Context, namespace string, filter TaskFilter) ([]*ExecutionStep, error)
ListTasks lists WAITING human/interactive tasks.
func (*Engine) MergeVars ¶
func (e *Engine) MergeVars(ctx context.Context, namespace, execID string, vars map[string]interface{}) error
MergeVars merges into durable execution variables.
func (*Engine) N8NHandler ¶
func (e *Engine) N8NHandler(opts N8NHandlerOptions) http.Handler
N8NHandler serves the entry points of imported workflows in a namespace: /webhook/{path} (Webhook, Telegram/WhatsApp triggers), /chat/{workflowID} and /form/{workflowID}. Mount it under a prefix, e.g.
http.Handle("/n8n/", http.StripPrefix("/n8n", engine.N8NHandler(flow.N8NHandlerOptions{Namespace: "default"})))
func (*Engine) ReapTimeouts ¶
ReapTimeouts checks for and handles timed-out tasks
func (*Engine) RegisterWorkflow ¶
RegisterWorkflow saves a workflow definition
func (*Engine) ReleaseTask ¶
ReleaseTask releases a claimed human task.
func (*Engine) RollbackTo ¶
func (e *Engine) RollbackTo(ctx context.Context, namespace, execID, nodeID, reason, actor string) error
RollbackTo journals and enqueues compensation toward a node.
func (*Engine) SetAuthProvider ¶
func (e *Engine) SetAuthProvider(provider AuthProvider) *Engine
SetAuthProvider sets authorization for the engine and CronManager.
func (*Engine) SetEventBus ¶
SetEventBus replaces the engine event bus and rewires CronManager.
func (*Engine) SetHostHooks ¶
func (e *Engine) SetHostHooks(h EventHandler) *Engine
SetHostHooks wires a synchronous host integration handler (e.g. WebSocket bridge).
func (*Engine) SetOutboundPolicy ¶
func (e *Engine) SetOutboundPolicy(p OutboundPolicy) *Engine
SetOutboundPolicy replaces the network policy of the built-in "http" and "notify" nodes registered by NewEngine. By default they may only reach public internet addresses (SSRF protection); use AllowedHosts or AllowPrivateNetworks to reach internal services.
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) SignalExecution ¶
func (e *Engine) SignalExecution(ctx context.Context, namespace, execID, nodeID, output string) error
SignalExecution sends a signal to resume a waiting workflow
func (*Engine) StartWorker ¶
StartWorker starts a worker that processes tasks one at a time. It blocks until ctx is cancelled; in-flight steps are released back to the queue on shutdown.
func (*Engine) StartWorkerWithOptions ¶
func (e *Engine) StartWorkerWithOptions(ctx context.Context, namespace, workerID string, opts WorkerOptions)
StartWorkerWithOptions starts a worker with custom concurrency and polling.
go engine.StartWorkerWithOptions(ctx, "default", "worker-1", flow.WorkerOptions{Concurrency: 16})
type EventBus ¶
EventBus manages event subscriptions
func NewEventBus ¶
func NewEventBus() *EventBus
NewEventBus creates a new event bus
Example:
eventBus := flow.NewEventBus() eventBus.RegisterHandler(flow.EventWorkflowCompleted, myHandler)
func (*EventBus) RegisterGlobalHandler ¶
func (eb *EventBus) RegisterGlobalHandler(handler EventHandler)
RegisterGlobalHandler registers a handler for all events
func (*EventBus) RegisterHandler ¶
func (eb *EventBus) RegisterHandler(eventType EventType, handler EventHandler)
RegisterHandler registers a handler for a specific event type
type ExecutionStep ¶
type ExecutionStep = models.ExecutionStep
type HandlerFunc ¶
type HandlerFunc func(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error)
HandlerFunc is the signature for workflow functions
Example:
func ProcessOrder(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error) {
orderID := input["order_id"].(string)
// ... process order ...
return map[string]interface{}{"status": "processed"}, nil
}
type LegacyStep ¶
type LegacyStep = models.LegacyStep
LegacyStep describes a linear/legacy workflow step for ImportStepChain.
type N8NChatMemoryReplacer ¶
type N8NChatMemoryReplacer = n8n.ChatMemoryReplacer
N8NChatMemoryReplacer is an optional extension of N8NChatMemoryStore used by the Chat Memory Manager's override and delete modes.
type N8NChatMemoryStore ¶
type N8NChatMemoryStore = n8n.ChatMemoryStore
N8NChatMemoryStore stores AI chat history for memory nodes.
type N8NCredentialProvider ¶
type N8NCredentialProvider = n8n.CredentialProvider
N8NCredentialProvider resolves n8n credentials (back it with a vault).
type N8NCredentialRef ¶
type N8NCredentialRef = n8n.CredentialRef
N8NCredentialRef identifies a credential referenced by an n8n node.
type N8NHandlerOptions ¶
type N8NHandlerOptions = n8n.HandlerOptions
N8NHandlerOptions configures the n8n webhook/chat/form HTTP handler.
type N8NImportOptions ¶
type N8NImportOptions = n8n.ImportOptions
N8NImportOptions configures ImportN8NWorkflow.
type N8NInstallOptions ¶
type N8NInstallOptions struct {
N8NImportOptions
// AllowPartial registers the workflow even when the report has blocking
// issues (nodes that are not supported fail when reached).
AllowPartial bool
// SkipSchedules does not create schedules for Schedule Trigger nodes.
SkipSchedules bool
}
N8NInstallOptions configures InstallN8NWorkflow.
type N8NInstallResult ¶
N8NInstallResult is returned by InstallN8NWorkflow.
type N8NItem ¶
N8NItem is one n8n data item.
func N8NOutputItems ¶
N8NOutputItems decodes the items of an n8n step or execution output.
type N8NOptions ¶
N8NOptions configures the n8n runtime (credentials, outbound network policy, chat memory, timeouts, timezone).
type N8NPollStateStore ¶
type N8NPollStateStore = n8n.PollStateStore
N8NPollStateStore persists polling trigger cursors.
type N8NPollStateSwapper ¶
type N8NPollStateSwapper = n8n.PollStateSwapper
N8NPollStateSwapper is an optional extension of N8NPollStateStore that advances cursors atomically so overlapping polls never emit duplicates.
type N8NStaticCredentials ¶
type N8NStaticCredentials = n8n.StaticCredentials
N8NStaticCredentials is an in-memory N8NCredentialProvider.
func NewN8NStaticCredentials ¶
func NewN8NStaticCredentials() *N8NStaticCredentials
NewN8NStaticCredentials returns an empty in-memory credential store.
type N8NTrigger ¶
type N8NTrigger = n8n.TriggerSpec
N8NTrigger describes one way an imported workflow can be started.
type NodeBuilder ¶
type NodeBuilder struct {
*builder.NodeBuilder
}
NodeBuilder provides a fluent API for configuring nodes
func (*NodeBuilder) If ¶
func (nb *NodeBuilder) If(targetID, condition string) *NodeBuilder
If creates a conditional connection
func (*NodeBuilder) Then ¶
func (nb *NodeBuilder) Then(targetID string) *NodeBuilder
Then connects this node to the next node
func (*NodeBuilder) WithConfig ¶
func (nb *NodeBuilder) WithConfig(key string, value interface{}) *NodeBuilder
WithConfig adds configuration to a node
func (*NodeBuilder) WithRetry ¶
func (nb *NodeBuilder) WithRetry(count int) *NodeBuilder
WithRetry sets retry count
func (*NodeBuilder) WithSaga ¶
func (nb *NodeBuilder) WithSaga(compensateNodeID string) *NodeBuilder
WithSaga sets a compensation node (saga pattern)
type NodeExecutor ¶
type NodeExecutor = engine.NodeExecutor
NodeExecutor defines the interface for custom node types
type OutboundPolicy ¶
type OutboundPolicy = node.OutboundPolicy
OutboundPolicy controls which network destinations the built-in http and notify nodes may reach, plus response size and timeout limits.
type PermanentError ¶
type PermanentError = engine.PermanentError
PermanentError marks executor errors that should not be retried. Return an error implementing it from a custom node to skip the retry policy.
type Registry ¶
Registry manages workflow function handlers
func (*Registry) Get ¶
func (r *Registry) Get(nodeType string) (NodeExecutor, error)
Get retrieves a registered executor by type
func (*Registry) Register ¶
func (r *Registry) Register(nodeType string, executor NodeExecutor)
Register registers a custom node executor
func (*Registry) RegisterFunction ¶
func (r *Registry) RegisterFunction(name string, handler HandlerFunc)
RegisterFunction registers a function handler
Example:
registry.RegisterFunction("SendEmail", func(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error) {
email := input["email"].(string)
// Send email...
return map[string]interface{}{"sent": true}, nil
})
type RetryPolicy ¶
type RetryPolicy = models.RetryPolicy
type SQLStorageOptions ¶
SQLStorageOptions configures table prefix and migrations.
type ScheduleListFilter ¶
type ScheduleListFilter = trigger.ScheduleListFilter
ScheduleListFilter filters ListSchedules results.
type ScheduleOpts ¶
type ScheduleOpts = trigger.ScheduleOpts
ScheduleOpts configures optional schedule create behavior.
type ScheduleUpdateOpts ¶
type ScheduleUpdateOpts = trigger.ScheduleUpdateOpts
ScheduleUpdateOpts is a partial update patch for schedules.
type Storage ¶
Storage interface for persistence
func NewMemoryStorage ¶
func NewMemoryStorage() Storage
NewMemoryStorage creates an in-memory storage backend (for development)
func NewMySQLStorage ¶
NewMySQLStorage creates a MySQL storage backend with auto-migration
func NewMySQLStorageWithOptions ¶
func NewMySQLStorageWithOptions(db *sqlx.DB, opts SQLStorageOptions) (Storage, error)
NewMySQLStorageWithOptions creates MySQL storage with prefix / migrate options.
func NewPostgreSQLStorage ¶
NewPostgreSQLStorage creates a PostgreSQL storage backend with auto-migration
func NewPostgreSQLStorageWithOptions ¶
func NewPostgreSQLStorageWithOptions(db *sqlx.DB, opts SQLStorageOptions) (Storage, error)
NewPostgreSQLStorageWithOptions creates Postgres storage with options.
func NewRedisStorage ¶
NewRedisStorage creates a Redis storage backend
Example:
storage := flow.NewRedisStorage("localhost:6379", "", 0)
func NewSQLStorageFromDB ¶
NewSQLStorageFromDB wraps database/sql.DB (dialect: "mysql" or "postgres").
type TaskStatus ¶
type TaskStatus = models.TaskStatus
type WebhookManager ¶
type WebhookManager struct {
*trigger.WebhookManager
}
WebhookManager handles HTTP webhook triggers
func NewWebhookManager ¶
func NewWebhookManager(eng *Engine) *WebhookManager
NewWebhookManager creates a webhook handler
Example:
webhookMgr := flow.NewWebhookManager(engine)
http.Handle("/webhooks/", webhookMgr)
POST /webhooks/{namespace}/{workflow_id} with JSON body to trigger workflows
func (*WebhookManager) ServeHTTP ¶
func (w *WebhookManager) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP handles webhook requests
type Worker ¶
Worker executes workflow tasks
func (*Worker) SetConcurrency ¶
SetConcurrency sets how many steps the worker runs in parallel.
func (*Worker) SetNamespace ¶
SetNamespace sets the worker's namespace
type WorkerOptions ¶
type WorkerOptions = engine.WorkerOptions
WorkerOptions configures worker concurrency and polling.
type Workflow ¶
func ImportStepChain ¶
func ImportStepChain(id, name string, steps []LegacyStep) (*Workflow, error)
ImportStepChain converts a linear/legacy step list into a Workflow DAG.
type WorkflowBuilder ¶
type WorkflowBuilder struct {
*builder.WorkflowBuilder
}
WorkflowBuilder provides a fluent API for building workflows
func NewWorkflow ¶
func NewWorkflow(id, name string) *WorkflowBuilder
NewWorkflow creates a new workflow builder
Example:
wf := flow.NewWorkflow("order-processing", "Order Processing Workflow").
AddNode("validate", flow.NodeTypeFunction).
WithConfig("functionName", "ValidateOrder").
Then("process").
AddNode("process", flow.NodeTypeFunction).
WithConfig("functionName", "ProcessOrder").
Build()
func (*WorkflowBuilder) AddNode ¶
func (b *WorkflowBuilder) AddNode(id, nodeType string) *NodeBuilder
AddNode adds a node to the workflow
func (*WorkflowBuilder) Build ¶
func (b *WorkflowBuilder) Build() *Workflow
Build returns the completed workflow
func (*WorkflowBuilder) Connect ¶
func (b *WorkflowBuilder) Connect(sourceID, targetID string) *WorkflowBuilder
Connect creates an edge between two nodes
func (*WorkflowBuilder) ConnectIf ¶
func (b *WorkflowBuilder) ConnectIf(sourceID, targetID, condition string) *WorkflowBuilder
ConnectIf creates a conditional edge
func (*WorkflowBuilder) Visualize ¶
func (b *WorkflowBuilder) Visualize() string
Visualize generates a Mermaid diagram of the workflow
type WorkflowStatus ¶
type WorkflowStatus = models.WorkflowStatus
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
auth
command
|
|
|
interactive_approval
command
|
|
|
n8n
command
Command n8n runs n8n workflow exports on the flow engine.
|
Command n8n runs n8n workflow exports on the flow engine. |
|
internal
|
|
|
n8n
Package n8n runs n8n workflow definitions on the flow engine.
|
Package n8n runs n8n workflow definitions on the flow engine. |