workflowmanager

package
v0.19.978 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CANHintChecker

type CANHintChecker interface {
	// CheckCANHint returns true if a continue-as-new has been requested.
	CheckCANHint(ctx workflow.Context) (bool, error)

	// ClearCANHint clears the hint so subsequent checks don't re-trigger.
	ClearCANHint(ctx workflow.Context) error
}

CANHintChecker checks for externally-requested continue-as-new hints. Implementations typically check a metadata flag in the database.

type CANHintCheckerFunc

type CANHintCheckerFunc struct {
	CheckFn func(ctx workflow.Context) (bool, error)
	ClearFn func(ctx workflow.Context) error
}

CANHintCheckerFunc adapts a pair of functions into a CANHintChecker.

func (CANHintCheckerFunc) CheckCANHint

func (f CANHintCheckerFunc) CheckCANHint(ctx workflow.Context) (bool, error)

func (CANHintCheckerFunc) ClearCANHint

func (f CANHintCheckerFunc) ClearCANHint(ctx workflow.Context) error

type CANResponse

type CANResponse struct {
	WorkflowType  string `json:"workflow_type"`
	Namespace     string `json:"namespace"`
	HistoryLength int    `json:"history_length"`
	HistoryMax    int    `json:"history_max"`
	HintRequested bool   `json:"hint_requested"`
	Restarting    bool   `json:"restarting"`
}

CANResponse holds diagnostic info from a continue-as-new check.

type Manager

type Manager struct {
	// Stopped is set to true when the backing entity no longer exists
	// or the workflow has expired.
	Stopped bool

	// Restarted is set to true when a continue-as-new is needed
	// (history too large, hint requested, or error recovery).
	Restarted bool
	// contains filtered or unexported fields
}

Manager manages the lifecycle of a long-running workflow, providing continue-as-new checks, alive checks, and expiry checks in a single background goroutine. Callers read Stopped and Restarted to decide how to proceed in their main workflow.Await loop.

func New

func New(opts ...Option) *Manager

New creates a Manager with the given options.

func (*Manager) RunCANCheck

func (m *Manager) RunCANCheck(ctx workflow.Context) (bool, *CANResponse)

RunCANCheck performs a single continue-as-new check on demand. Returns whether a restart should be triggered, along with diagnostics.

func (*Manager) Start

func (m *Manager) Start(ctx workflow.Context)

Start begins the background lifecycle goroutine. It periodically runs CAN checks, alive checks, and expiry checks, setting Stopped or Restarted as appropriate. Returns immediately.

type Option

type Option func(*options)

Option configures a Manager.

func WithAliveChecker

func WithAliveChecker(fn func(ctx workflow.Context) (bool, error)) Option

WithAliveChecker provides a function that verifies the backing entity still exists. When it returns (false, nil), the manager sets Stopped=true.

func WithCANHintChecker

func WithCANHintChecker(c CANHintChecker) Option

WithCANHintChecker provides a checker for externally-requested continue-as-new hints (e.g., metadata flags in the database).

func WithCheckInterval

func WithCheckInterval(d time.Duration) Option

WithCheckInterval sets how often the background goroutine runs checks. Defaults to 3 minutes. Up to 50% jitter is added automatically.

func WithExpiryChecker

func WithExpiryChecker(fn func(ctx workflow.Context) (*time.Time, error)) Option

WithExpiryChecker provides a function that returns when the workflow should terminate. If the returned time is in the past, the manager sets Stopped=true.

func WithHistoryMax

func WithHistoryMax(n int) Option

WithHistoryMax sets the maximum workflow history length before triggering continue-as-new. Defaults to 10000.

func WithMetricsWriter

func WithMetricsWriter(mw tmetrics.Writer) Option

WithMetricsWriter sets the metrics writer for reporting workflow size gauges.

func WithOnStopped

func WithOnStopped(fn func(ctx workflow.Context)) Option

WithOnStopped provides a callback invoked when the manager sets Stopped=true. Useful for writing terminal status to DB before the workflow exits.

Jump to

Keyboard shortcuts

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