Documentation
¶
Index ¶
- type Step
- type StepOption
- type StepType
- type Workflow
- func (w *Workflow) Branch(name string, branches ...*Workflow) *Workflow
- func (w *Workflow) Condition(fn func(fh.Ctx) bool) *Workflow
- func (w *Workflow) Handler() fh.HandlerFunc
- func (w *Workflow) Job(name, jobType string, conditions ...func(fh.Ctx) bool) *Workflow
- func (w *Workflow) OnComplete(fn func(err error, dur time.Duration)) *Workflow
- func (w *Workflow) OnError(fn func(step string, err error) error) *Workflow
- func (w *Workflow) OnStepComplete(fn func(step string, err error, dur time.Duration)) *Workflow
- func (w *Workflow) OnStepStart(fn func(step string)) *Workflow
- func (w *Workflow) Parallel(name string, branches ...*Workflow) *Workflow
- func (w *Workflow) ParallelJoin(name string, branches ...*Workflow) *Workflow
- func (w *Workflow) Use(name string, handler fh.HandlerFunc, conditions ...func(fh.Ctx) bool) *Workflow
- func (w *Workflow) UseWithOptions(name string, handler fh.HandlerFunc, opts ...StepOption) *Workflow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Step ¶
type Step struct {
Name string
Type StepType
Handler fh.HandlerFunc
JobType string
Condition func(fh.Ctx) bool
Branches []*Workflow
// Timeout bounds a StepSync handler's execution. If <= 0, no deadline is applied.
// The step observes fh.Ctx.Context() the same way mw/timeout does; it is the
// handler's responsibility to check ctx.Done() for long-running work.
Timeout time.Duration
// RetryAttempts is the number of additional attempts after the first failure
// for a StepSync handler. 0 means no retry.
RetryAttempts int
// RetryBackoff is the delay between retry attempts. Ignored if RetryAttempts is 0.
RetryBackoff time.Duration
// ParallelFailFast controls StepParallel behavior. When true (default), the
// first branch error cancels the workflow. When false, all branches run to
// completion and their errors are joined.
ParallelFailFast bool
}
Step is one unit of work inside a Workflow.
type StepOption ¶
type StepOption func(*Step)
StepOption configures a Step registered through UseWithOptions.
func WithCondition ¶
func WithCondition(fn func(fh.Ctx) bool) StepOption
WithCondition only runs the step when fn returns true.
func WithRetry ¶
func WithRetry(attempts int, backoff time.Duration) StepOption
WithRetry retries a failed step up to attempts additional times, waiting backoff between attempts. Retries stop early if the context is done.
func WithTimeout ¶
func WithTimeout(d time.Duration) StepOption
WithTimeout bounds the step's execution time via a deadline context.
type Workflow ¶
Workflow is an ordered, composable sequence of steps executed as middleware.
func (*Workflow) Branch ¶
Branch runs the first branch whose Condition passes (or the first unconditional branch), then stops evaluating further branches.
func (*Workflow) Handler ¶
func (w *Workflow) Handler() fh.HandlerFunc
Handler returns the fh.HandlerFunc that executes this workflow.
func (*Workflow) Job ¶
Job appends an async step that hands the request off to the durable queue via fh.AtomicHandoff instead of running inline.
func (*Workflow) OnComplete ¶
OnComplete registers an observability hook called after the whole workflow finishes.
func (*Workflow) OnError ¶
OnError registers a compensation hook invoked when a step returns an error. If the hook returns nil, the workflow continues to the next step instead of aborting. This is intended for compensating transactions (e.g. releasing a reservation made by an earlier step). Panics inside steps are converted to errors and also routed through this hook.
func (*Workflow) OnStepComplete ¶
OnStepComplete registers an observability hook called after each step finishes.
func (*Workflow) OnStepStart ¶
OnStepStart registers an observability hook called before each step runs.
func (*Workflow) Parallel ¶
Parallel runs all branches concurrently and fails fast on the first error.
func (*Workflow) ParallelJoin ¶
ParallelJoin runs all branches concurrently, always waits for every branch to finish, and returns a joined error if any branch failed.
func (*Workflow) Use ¶
func (w *Workflow) Use(name string, handler fh.HandlerFunc, conditions ...func(fh.Ctx) bool) *Workflow
Use appends a synchronous step. conditions[0], if given, gates the step.
func (*Workflow) UseWithOptions ¶
func (w *Workflow) UseWithOptions(name string, handler fh.HandlerFunc, opts ...StepOption) *Workflow
UseWithOptions appends a synchronous step configured with timeout/retry/condition options.