Documentation
¶
Index ¶
- type Definition
- type Engine
- func (e *Engine) Cancel(ctx context.Context, runID string) error
- func (e *Engine) Dispatch(name string, payload Payload) (string, error)
- func (e *Engine) DispatchSync(ctx context.Context, name string, payload Payload) (*RunInstance, error)
- func (e *Engine) List(ctx context.Context, workflow string, limit int) ([]*RunInstance, error)
- func (e *Engine) Register(def *Definition)
- func (e *Engine) SetHooks(h EngineHooks)
- func (e *Engine) Signal(runID, event string, data Payload) error
- func (e *Engine) Status(ctx context.Context, runID string) (*RunInstance, error)
- func (e *Engine) Workflows() []string
- type EngineHooks
- type MemoryStore
- func (s *MemoryStore) Delete(_ context.Context, id string) error
- func (s *MemoryStore) List(_ context.Context, workflow string, limit int) ([]*RunInstance, error)
- func (s *MemoryStore) Load(_ context.Context, id string) (*RunInstance, error)
- func (s *MemoryStore) Save(_ context.Context, run *RunInstance) error
- type Payload
- type Run
- type RunInstance
- type RunStatus
- type StepBuilder
- func (b *StepBuilder) After(deps ...string) *StepBuilder
- func (b *StepBuilder) ContinueOnFailure() *StepBuilder
- func (b *StepBuilder) Parallel() *StepBuilder
- func (b *StepBuilder) Retry(max int, delay time.Duration) *StepBuilder
- func (b *StepBuilder) WaitForEvent(event string, timeout time.Duration) *StepBuilder
- func (b *StepBuilder) When(fn func(Payload) bool) *StepBuilder
- func (b *StepBuilder) WithTimeout(d time.Duration) *StepBuilder
- type StepDef
- type StepFunc
- type StepInstance
- type StepStatus
- type Store
- type WorkflowPlugin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Definition ¶
Definition describes a workflow template.
func Define ¶
func Define(name string, builder func(r *Run)) *Definition
Define creates a workflow definition.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates workflow execution.
func (*Engine) DispatchSync ¶
func (e *Engine) DispatchSync(ctx context.Context, name string, payload Payload) (*RunInstance, error)
DispatchSync starts a workflow and blocks until completion.
func (*Engine) Register ¶
func (e *Engine) Register(def *Definition)
Register adds a workflow definition to the engine.
func (*Engine) SetHooks ¶
func (e *Engine) SetHooks(h EngineHooks)
SetHooks configures lifecycle hooks.
type EngineHooks ¶
type EngineHooks struct {
OnStepStart func(runID, step string)
OnStepComplete func(runID, step string, output Payload, duration time.Duration)
OnStepFail func(runID, step string, err error, attempt int)
OnRunComplete func(runID, workflow string, payload Payload)
OnRunFail func(runID, workflow string, err error)
}
EngineHooks allows observability into workflow execution.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore provides an in-memory Store implementation.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) List ¶
func (s *MemoryStore) List(_ context.Context, workflow string, limit int) ([]*RunInstance, error)
func (*MemoryStore) Load ¶
func (s *MemoryStore) Load(_ context.Context, id string) (*RunInstance, error)
func (*MemoryStore) Save ¶
func (s *MemoryStore) Save(_ context.Context, run *RunInstance) error
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run is the build context passed to the definition function.
type RunInstance ¶
type RunInstance struct {
ID string `json:"id"`
Workflow string `json:"workflow"`
Status RunStatus `json:"status"`
Payload Payload `json:"payload"`
Steps map[string]*StepInstance `json:"steps"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
Error string `json:"error,omitempty"`
}
RunInstance holds the state of a running workflow.
type StepBuilder ¶
type StepBuilder struct {
// contains filtered or unexported fields
}
StepBuilder provides a fluent API for defining steps.
func (*StepBuilder) After ¶
func (b *StepBuilder) After(deps ...string) *StepBuilder
func (*StepBuilder) ContinueOnFailure ¶
func (b *StepBuilder) ContinueOnFailure() *StepBuilder
func (*StepBuilder) Parallel ¶
func (b *StepBuilder) Parallel() *StepBuilder
func (*StepBuilder) Retry ¶
func (b *StepBuilder) Retry(max int, delay time.Duration) *StepBuilder
func (*StepBuilder) WaitForEvent ¶
func (b *StepBuilder) WaitForEvent(event string, timeout time.Duration) *StepBuilder
func (*StepBuilder) When ¶
func (b *StepBuilder) When(fn func(Payload) bool) *StepBuilder
func (*StepBuilder) WithTimeout ¶
func (b *StepBuilder) WithTimeout(d time.Duration) *StepBuilder
type StepDef ¶
type StepDef struct {
Name string
Fn StepFunc
DependsOn []string // steps that must complete first
IsParallel bool // can run in parallel with siblings
MaxRetries int // 0 = no retries
RetryDelay time.Duration // delay between retries
Timeout time.Duration // per-execution timeout
WaitEvent string // external event to wait for
WaitTimeout time.Duration // how long to wait for the event
Condition func(Payload) bool
OnFailure string // "continue" | "abort" (default: abort)
}
StepDef describes a single step in a workflow.
type StepInstance ¶
type StepInstance struct {
Name string `json:"name"`
Status StepStatus `json:"status"`
Output Payload `json:"output,omitempty"`
Error string `json:"error,omitempty"`
Attempts int `json:"attempts"`
StartedAt *time.Time `json:"started_at,omitempty"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
Duration time.Duration `json:"duration_ms,omitempty"`
}
StepInstance holds the state of a step within a running workflow.
type StepStatus ¶
type StepStatus string
StepStatus tracks the lifecycle of a step.
const ( StatusPending StepStatus = "pending" StatusRunning StepStatus = "running" StatusCompleted StepStatus = "completed" StatusFailed StepStatus = "failed" StatusSkipped StepStatus = "skipped" StatusWaiting StepStatus = "waiting" // waiting for external event StatusCancelled StepStatus = "cancelled" )
type Store ¶
type Store interface {
Save(ctx context.Context, run *RunInstance) error
Load(ctx context.Context, id string) (*RunInstance, error)
List(ctx context.Context, workflow string, limit int) ([]*RunInstance, error)
Delete(ctx context.Context, id string) error
}
Store persists workflow run state.
type WorkflowPlugin ¶
type WorkflowPlugin struct {
nimbus.BasePlugin
Engine *Engine
}
WorkflowPlugin integrates the workflow engine with Nimbus.
func NewPlugin ¶
func NewPlugin(store Store) *WorkflowPlugin
NewPlugin creates a new workflow plugin.
func (*WorkflowPlugin) DefaultConfig ¶
func (p *WorkflowPlugin) DefaultConfig() map[string]any
func (*WorkflowPlugin) RegisterRoutes ¶
func (p *WorkflowPlugin) RegisterRoutes(r *router.Router)
RegisterRoutes mounts workflow API routes.