Documentation
¶
Index ¶
- type CANHintChecker
- type CANHintCheckerFunc
- type CANResponse
- type Manager
- type Option
- func WithAliveChecker(fn func(ctx workflow.Context) (bool, error)) Option
- func WithCANHintChecker(c CANHintChecker) Option
- func WithCheckInterval(d time.Duration) Option
- func WithExpiryChecker(fn func(ctx workflow.Context) (*time.Time, error)) Option
- func WithHistoryMax(n int) Option
- func WithMetricsWriter(mw tmetrics.Writer) Option
- func WithOnStopped(fn func(ctx workflow.Context)) Option
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 (*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.
type Option ¶
type Option func(*options)
Option configures a Manager.
func WithAliveChecker ¶
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 ¶
WithCheckInterval sets how often the background goroutine runs checks. Defaults to 3 minutes. Up to 50% jitter is added automatically.
func WithExpiryChecker ¶
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 ¶
WithHistoryMax sets the maximum workflow history length before triggering continue-as-new. Defaults to 10000.
func WithMetricsWriter ¶
WithMetricsWriter sets the metrics writer for reporting workflow size gauges.
func WithOnStopped ¶
WithOnStopped provides a callback invoked when the manager sets Stopped=true. Useful for writing terminal status to DB before the workflow exits.