workflow

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureAuditTables

func EnsureAuditTables(ctx context.Context, db *sql.DB) error

func RecordTransition

func RecordTransition(ctx context.Context, db *sql.DB, ev TransitionAudit) error

Types

type InstanceState

type InstanceState struct {
	Site       string          `json:"site"`
	Workflow   string          `json:"workflow"`
	InstanceID string          `json:"instance_id"`
	Version    int64           `json:"version"`
	LeaseOwner string          `json:"lease_owner"`
	LeaseUntil time.Time       `json:"lease_until"`
	TimerID    string          `json:"timer_id,omitempty"`
	NextWakeAt time.Time       `json:"next_wake_at,omitempty"`
	WakeAt     time.Time       `json:"wake_at,omitempty"`
	Status     string          `json:"status"`
	Payload    json.RawMessage `json:"payload,omitempty"`
	UpdatedAt  time.Time       `json:"updated_at"`
}

InstanceState is the persisted workflow actor state used for lease/fencing and timer recovery.

type LeaseStore

type LeaseStore struct {
	DB *sql.DB
}

LeaseStore persists and fences actor ownership.

func (*LeaseStore) Acquire

func (s *LeaseStore) Acquire(ctx context.Context, site, workflow, instanceID, owner string, ttl time.Duration) (InstanceState, error)

func (*LeaseStore) EnsureTables

func (s *LeaseStore) EnsureTables(ctx context.Context) error

func (*LeaseStore) Load

func (s *LeaseStore) Load(ctx context.Context, site, workflow, instanceID string) (InstanceState, error)

func (*LeaseStore) Release

func (s *LeaseStore) Release(ctx context.Context, site, workflow, instanceID, owner string) error

func (*LeaseStore) Renew

func (s *LeaseStore) Renew(ctx context.Context, site, workflow, instanceID, owner string, ttl time.Duration) (InstanceState, error)

func (*LeaseStore) Upsert

func (s *LeaseStore) Upsert(ctx context.Context, st InstanceState) error

type QueueMetrics

type QueueMetrics struct {
	DueTimers       int64
	LeasedActors    int64
	NextLeaseExpiry time.Time
}

func CollectMetrics

func CollectMetrics(ctx context.Context, db *sql.DB, now time.Time) (QueueMetrics, error)

type Runtime

type Runtime struct {
	LeaseStore     *LeaseStore
	TimerScheduler *TimerScheduler
	StepHandler    StepHandler
	LeaseTTL       time.Duration
}

Runtime wires lease/fencing, timers, and step execution together.

func NewRuntime

func NewRuntime(db *sql.DB, handler StepHandler) *Runtime

func (*Runtime) DeadLetter

func (r *Runtime) DeadLetter(ctx context.Context, state InstanceState, cause string) error

DeadLetter persists a terminal failure state for operator recovery.

func (*Runtime) Ensure

func (r *Runtime) Ensure(ctx context.Context) error

Ensure prepares the workflow tables needed by the runtime.

func (*Runtime) Pause

func (r *Runtime) Pause(ctx context.Context, state InstanceState, owner string) error

Pause records a paused state and clears the lease.

func (*Runtime) ProcessDue

func (r *Runtime) ProcessDue(ctx context.Context, now time.Time, limit int, owner string) ([]InstanceState, error)

ProcessDue resumes any due workflow instances using the supplied owner identity. It is a small recovery loop for timer-driven workflows and returns the states that were successfully resumed.

func (*Runtime) Resume

func (r *Runtime) Resume(ctx context.Context, site, workflowName, instanceID, owner string) (InstanceState, error)

Resume acquires the actor lease, executes the step handler, and persists the resulting state. It returns the updated state for the caller to continue from.

func (*Runtime) Retry

func (r *Runtime) Retry(ctx context.Context, state InstanceState, after time.Duration) error

Retry marks an instance for retry and pushes a new wakeup.

type StepHandler

type StepHandler func(ctx context.Context, state InstanceState, doc *doctype.Document) (InstanceState, error)

StepHandler executes one workflow step against a document snapshot.

type TimerScheduler

type TimerScheduler struct {
	DB *sql.DB
}

TimerScheduler tracks due workflow wakeups with SQL persistence.

func (*TimerScheduler) Delete

func (s *TimerScheduler) Delete(ctx context.Context, site, workflow, instanceID string) error

func (*TimerScheduler) DeleteAt

func (s *TimerScheduler) DeleteAt(ctx context.Context, site, workflow, instanceID string, wakeAt time.Time) error

func (*TimerScheduler) DeleteID

func (s *TimerScheduler) DeleteID(ctx context.Context, site, workflow, instanceID, timerID string) error

func (*TimerScheduler) Due

func (s *TimerScheduler) Due(ctx context.Context, now time.Time, limit int) ([]InstanceState, error)

func (*TimerScheduler) EnsureTables

func (s *TimerScheduler) EnsureTables(ctx context.Context) error

func (*TimerScheduler) Schedule

func (s *TimerScheduler) Schedule(ctx context.Context, site, workflow, instanceID, timerID string, wakeAt time.Time, payload json.RawMessage) error

type TransitionAudit

type TransitionAudit struct {
	ID         string
	Site       string
	Workflow   string
	InstanceID string
	StepID     string
	Kind       string
	FromState  string
	ToState    string
	Cause      string
	CreatedAt  time.Time
}

Jump to

Keyboard shortcuts

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