workflow

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	Name  string
	Steps []*StepDef
}

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 NewEngine

func NewEngine(store Store) *Engine

NewEngine creates a new workflow engine.

func (*Engine) Cancel

func (e *Engine) Cancel(ctx context.Context, runID string) error

Cancel cancels a running workflow.

func (*Engine) Dispatch

func (e *Engine) Dispatch(name string, payload Payload) (string, error)

Dispatch starts a new workflow run asynchronously.

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) List

func (e *Engine) List(ctx context.Context, workflow string, limit int) ([]*RunInstance, error)

List returns recent runs for a workflow.

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.

func (*Engine) Signal

func (e *Engine) Signal(runID, event string, data Payload) error

Signal sends an external event to a waiting workflow step.

func (*Engine) Status

func (e *Engine) Status(ctx context.Context, runID string) (*RunInstance, error)

Status returns the current state of a workflow run.

func (*Engine) Workflows

func (e *Engine) Workflows() []string

Workflows returns all registered workflow names.

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) Delete

func (s *MemoryStore) Delete(_ context.Context, id string) error

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 Payload

type Payload map[string]any

Payload is the data bag passed through a workflow run.

type Run

type Run struct {
	// contains filtered or unexported fields
}

Run is the build context passed to the definition function.

func (*Run) Step

func (r *Run) Step(name string, fn StepFunc) *StepBuilder

Step registers a named step.

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 RunStatus

type RunStatus string

RunStatus tracks the lifecycle of a workflow run.

const (
	RunPending   RunStatus = "pending"
	RunRunning   RunStatus = "running"
	RunCompleted RunStatus = "completed"
	RunFailed    RunStatus = "failed"
	RunCancelled RunStatus = "cancelled"
	RunPaused    RunStatus = "paused" // waiting for human input
)

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 StepFunc

type StepFunc func(ctx context.Context, payload Payload) (Payload, error)

StepFunc performs a single unit of work within 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) Boot

func (p *WorkflowPlugin) Boot(app *nimbus.App) error

func (*WorkflowPlugin) DefaultConfig

func (p *WorkflowPlugin) DefaultConfig() map[string]any

func (*WorkflowPlugin) Register

func (p *WorkflowPlugin) Register(app *nimbus.App) error

func (*WorkflowPlugin) RegisterRoutes

func (p *WorkflowPlugin) RegisterRoutes(r *router.Router)

RegisterRoutes mounts workflow API routes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL