wfruntime

package
v1.2.20 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 15 Imported by: ? 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

View Source
const InterruptedRunMessage = "server restarted before the run completed"

Variables

View Source
var (
	ErrAsyncTaskNotFound   = errors.New("async task not found")
	ErrAsyncTaskCancelled  = errors.New("async task is cancelled")
	ErrAsyncResultConflict = errors.New("async task already has a different result")
	ErrAsyncClaimLost      = errors.New("async task claim is no longer valid")
	ErrAsyncRunChanged     = errors.New("async task run has changed")
	ErrAsyncTaskExpired    = errors.New("async callback timeout")
)
View Source
var ErrRunNotFound = errors.New("run not found")

Functions

func CanTransition

func CanTransition(from, to Status) bool

func IsTerminal

func IsTerminal(status Status) bool

Types

type AsyncResultStore added in v1.2.20

type AsyncResultStore interface {
	CommitAsyncResult(ctx context.Context, task *AsyncTask, run *WorkflowRun, expectedUpdatedAt time.Time, snapshots []*RunSnapshot, events []RunEvent) error
}

AsyncResultStore atomically commits callback effects and their application marker under a live task/run claim. Implementations must reject stale claims, changed runs and cancelled tasks, without persisting any partial effects. The marker survives claim release so retries and loops cannot apply a callback twice even when its node is pending again or has a newer dispatch ID.

type AsyncTask added in v1.2.20

type AsyncTask struct {
	DispatchID     string                  `json:"dispatch_id"`
	RunID          string                  `json:"run_id"`
	NodeID         string                  `json:"node_id"`
	ExternalTaskID string                  `json:"external_task_id"`
	Task           executor.ExecuteTask    `json:"task"`
	Result         *executor.ExecuteResult `json:"result,omitempty"`
	ResultHash     string                  `json:"-"`
	ResultApplied  bool                    `json:"-"`
	// ExpireAt is the persisted callback deadline; zero means no expiration.
	ExpireAt   time.Time      `json:"expire_at,omitempty,omitzero"`
	State      AsyncTaskState `json:"state"`
	ClaimToken string         `json:"-"`
	ClaimUntil time.Time      `json:"-"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
}

type AsyncTaskState added in v1.2.20

type AsyncTaskState string
const (
	AsyncTaskWaiting   AsyncTaskState = "waiting"
	AsyncTaskCompleted AsyncTaskState = "completed"
	AsyncTaskClaimed   AsyncTaskState = "claimed"
	AsyncTaskDone      AsyncTaskState = "done"
	AsyncTaskCancelled AsyncTaskState = "cancelled"
)

type AsyncTaskStore added in v1.2.20

type AsyncTaskStore interface {
	SaveAsyncTask(ctx context.Context, task *AsyncTask) error
	SubmitAsyncResult(ctx context.Context, dispatchID string, result executor.ExecuteResult) (bool, error)
	// ClaimCompletedAsyncTasks also atomically completes expired waiting tasks
	// with a non-retryable timeout result before claiming recovery work.
	ClaimCompletedAsyncTasks(ctx context.Context, now time.Time, limit int, lease time.Duration) ([]*AsyncTask, error)
	RenewAsyncTask(ctx context.Context, dispatchID, claimToken string, claimUntil time.Time) (bool, error)
	AcknowledgeAsyncTask(ctx context.Context, dispatchID, claimToken string) error
	ReleaseAsyncTask(ctx context.Context, dispatchID, claimToken string) error
	CancelAsyncTasks(ctx context.Context, runID string) error
}

type EventType

type EventType string
const (
	EventRunStarted  EventType = "run_started"
	EventRunFinished EventType = "run_finished"
	EventRunPaused   EventType = "run_paused"
	EventRunResumed  EventType = "run_resumed"
	EventNodeReady   EventType = "node_ready"
	EventNodeRunning EventType = "node_running"
	EventNodeWaiting EventType = "node_waiting"
	EventNodeLoop    EventType = "node_loop"
	EventNodeRetry   EventType = "node_retry"
	EventNodeDone    EventType = "node_done"
	EventNodeFailed  EventType = "node_failed"
)

type GormStore

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

func NewGormStore deprecated

func NewGormStore(db *gorm.DB) (*GormStore, error)

NewGormStore constructs the legacy standalone runtime adapter.

Deprecated: new applications should compose the complete adapter through persist/gormstore.New. This constructor remains available for compatibility.

func NewGormStoreWithTablePrefix added in v1.2.13

func NewGormStoreWithTablePrefix(db *gorm.DB, tablePrefix string) (*GormStore, error)

func (*GormStore) AcknowledgeAsyncTask added in v1.2.20

func (s *GormStore) AcknowledgeAsyncTask(ctx context.Context, dispatchID, claimToken string) error

func (*GormStore) AppendEvent

func (s *GormStore) AppendEvent(ctx context.Context, event RunEvent) error

func (*GormStore) CancelAsyncTasks added in v1.2.20

func (s *GormStore) CancelAsyncTasks(ctx context.Context, runID string) error

func (*GormStore) ClaimCompletedAsyncTasks added in v1.2.20

func (s *GormStore) ClaimCompletedAsyncTasks(ctx context.Context, now time.Time, limit int, lease time.Duration) ([]*AsyncTask, error)

func (*GormStore) CommitAsyncResult added in v1.2.20

func (s *GormStore) CommitAsyncResult(ctx context.Context, task *AsyncTask, run *WorkflowRun, expectedUpdatedAt time.Time, snapshots []*RunSnapshot, events []RunEvent) error

func (*GormStore) Events

func (s *GormStore) Events(ctx context.Context, runID string) ([]RunEvent, error)

func (*GormStore) FailInterruptedRuns

func (s *GormStore) FailInterruptedRuns(ctx context.Context) (int, error)

func (*GormStore) ListRuns

func (s *GormStore) ListRuns(ctx context.Context) ([]*WorkflowRun, error)

func (*GormStore) LoadRun

func (s *GormStore) LoadRun(ctx context.Context, runID string) (*WorkflowRun, error)

func (*GormStore) ReleaseAsyncTask added in v1.2.20

func (s *GormStore) ReleaseAsyncTask(ctx context.Context, dispatchID, claimToken string) error

func (*GormStore) RenewAsyncTask added in v1.2.20

func (s *GormStore) RenewAsyncTask(ctx context.Context, dispatchID, claimToken string, claimUntil time.Time) (bool, error)

func (*GormStore) SaveAsyncTask added in v1.2.20

func (s *GormStore) SaveAsyncTask(ctx context.Context, task *AsyncTask) error

func (*GormStore) SaveRun

func (s *GormStore) SaveRun(ctx context.Context, run *WorkflowRun) error

func (*GormStore) SaveSnapshot

func (s *GormStore) SaveSnapshot(ctx context.Context, snapshot *RunSnapshot) error

func (*GormStore) Snapshots

func (s *GormStore) Snapshots(ctx context.Context, runID string) ([]*RunSnapshot, error)

func (*GormStore) SubmitAsyncResult added in v1.2.20

func (s *GormStore) SubmitAsyncResult(ctx context.Context, dispatchID string, result executor.ExecuteResult) (bool, error)

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) AcknowledgeAsyncTask added in v1.2.20

func (s *MemoryStore) AcknowledgeAsyncTask(ctx context.Context, dispatchID, claimToken string) error

func (*MemoryStore) AppendEvent

func (s *MemoryStore) AppendEvent(_ context.Context, event RunEvent) error

func (*MemoryStore) CancelAsyncTasks added in v1.2.20

func (s *MemoryStore) CancelAsyncTasks(_ context.Context, runID string) error

func (*MemoryStore) ClaimCompletedAsyncTasks added in v1.2.20

func (s *MemoryStore) ClaimCompletedAsyncTasks(_ context.Context, now time.Time, limit int, lease time.Duration) ([]*AsyncTask, error)

func (*MemoryStore) CommitAsyncResult added in v1.2.20

func (s *MemoryStore) CommitAsyncResult(ctx context.Context, task *AsyncTask, run *WorkflowRun, expectedUpdatedAt time.Time, snapshots []*RunSnapshot, events []RunEvent) error

func (*MemoryStore) Events

func (s *MemoryStore) Events(_ context.Context, runID string) ([]RunEvent, error)

func (*MemoryStore) ListRuns

func (s *MemoryStore) ListRuns(_ context.Context) ([]*WorkflowRun, error)

func (*MemoryStore) LoadRun

func (s *MemoryStore) LoadRun(_ context.Context, runID string) (*WorkflowRun, error)

func (*MemoryStore) ReleaseAsyncTask added in v1.2.20

func (s *MemoryStore) ReleaseAsyncTask(ctx context.Context, dispatchID, claimToken string) error

func (*MemoryStore) RenewAsyncTask added in v1.2.20

func (s *MemoryStore) RenewAsyncTask(_ context.Context, dispatchID, claimToken string, claimUntil time.Time) (bool, error)

func (*MemoryStore) SaveAsyncTask added in v1.2.20

func (s *MemoryStore) SaveAsyncTask(_ context.Context, task *AsyncTask) error

func (*MemoryStore) SaveRun

func (s *MemoryStore) SaveRun(_ context.Context, run *WorkflowRun) error

func (*MemoryStore) SaveSnapshot

func (s *MemoryStore) SaveSnapshot(_ context.Context, snapshot *RunSnapshot) error

func (*MemoryStore) Snapshots

func (s *MemoryStore) Snapshots(_ context.Context, runID string) ([]*RunSnapshot, error)

func (*MemoryStore) SubmitAsyncResult added in v1.2.20

func (s *MemoryStore) SubmitAsyncResult(_ context.Context, dispatchID string, result executor.ExecuteResult) (bool, error)

type NodeRun

type NodeRun struct {
	NodeID      string    `json:"node_id"`
	DispatchID  string    `json:"dispatch_id,omitempty"`
	Status      Status    `json:"status"`
	Attempt     int       `json:"attempt"`
	MaxAttempts int       `json:"max_attempts,omitempty"`
	StartedAt   time.Time `json:"started_at,omitempty"`
	FinishedAt  time.Time `json:"finished_at,omitempty"`
	// Input keeps the latest materialized task input so the UI can explain what
	// a node actually received during execution instead of only showing config.
	Input    any            `json:"input,omitempty"`
	Result   any            `json:"result,omitempty"`
	Error    string         `json:"error,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type RunContext

type RunContext struct {
	Variables   map[string]any `json:"variables,omitempty"`
	NodeResults map[string]any `json:"node_results,omitempty"`
}

type RunEvent

type RunEvent struct {
	RunID      string         `json:"run_id"`
	Type       EventType      `json:"type"`
	NodeID     string         `json:"node_id,omitempty"`
	Status     Status         `json:"status,omitempty"`
	Time       time.Time      `json:"time"`
	Message    string         `json:"message,omitempty"`
	Payload    map[string]any `json:"payload,omitempty"`
	WorkflowID string         `json:"workflow_id,omitempty"`
}

type RunSnapshot

type RunSnapshot struct {
	RunID       string              `json:"run_id"`
	Status      Status              `json:"status"`
	NodeRuns    map[string]*NodeRun `json:"node_runs"`
	Context     RunContext          `json:"context"`
	At          time.Time           `json:"at"`
	Description string              `json:"description,omitempty"`
}

type Status

type Status string
const (
	StatusPending   Status = "pending"
	StatusRunning   Status = "running"
	StatusWaiting   Status = "waiting"
	StatusSuccess   Status = "success"
	StatusFailed    Status = "failed"
	StatusRetry     Status = "retry"
	StatusPaused    Status = "paused"
	StatusCancelled Status = "cancelled"
	StatusTimeout   Status = "timeout"
)

type Store

type Store interface {
	SaveRun(ctx context.Context, run *WorkflowRun) error
	LoadRun(ctx context.Context, runID string) (*WorkflowRun, error)
	ListRuns(ctx context.Context) ([]*WorkflowRun, error)
	SaveSnapshot(ctx context.Context, snapshot *RunSnapshot) error
	Snapshots(ctx context.Context, runID string) ([]*RunSnapshot, error)
	AppendEvent(ctx context.Context, event RunEvent) error
	Events(ctx context.Context, runID string) ([]RunEvent, error)
}

type WorkflowRun

type WorkflowRun struct {
	ID                 string              `json:"id"`
	WorkflowID         string              `json:"workflow_id"`
	WorkflowVersionID  string              `json:"workflow_version_id"`
	PlanID             string              `json:"plan_id"`
	RequestFingerprint string              `json:"request_fingerprint,omitempty"`
	CredentialScope    string              `json:"credential_scope,omitempty"`
	Status             Status              `json:"status"`
	CurrentNodes       []string            `json:"current_nodes,omitempty"`
	NodeRuns           map[string]*NodeRun `json:"node_runs,omitempty"`
	Context            RunContext          `json:"context"`
	CreatedAt          time.Time           `json:"created_at"`
	UpdatedAt          time.Time           `json:"updated_at"`
	StartedAt          time.Time           `json:"started_at,omitempty"`
	FinishedAt         time.Time           `json:"finished_at,omitempty"`
	// contains filtered or unexported fields
}

func NewWorkflowRun

func NewWorkflowRun(runID, workflowID, versionID, planID string) *WorkflowRun

func (*WorkflowRun) Clone

func (r *WorkflowRun) Clone() *WorkflowRun

Jump to

Keyboard shortcuts

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