workflow

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package workflow builds typed DAGs of cron jobs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateStep = errors.New("workflow: duplicate step")
	ErrDuplicateDep  = errors.New("workflow: duplicate dependency")
	ErrUnknownDep    = errors.New("workflow: unknown dependency")
	ErrCycle         = errors.New("workflow: dependency cycle")
	ErrNilJob        = errors.New("workflow: step has no job")
	ErrInvalidName   = errors.New("workflow: invalid step name")
	ErrInvalidOption = errors.New("workflow: invalid option")
	ErrBuilderFrozen = errors.New("workflow: builder is frozen")
	ErrNilContext    = errors.New("workflow: nil context")
)

Errors reported while configuring or executing a workflow.

Functions

This section is empty.

Types

type Builder added in v0.5.3

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

Builder incrementally constructs one Workflow. Build freezes it. Builder is not safe for concurrent use; its zero value is ready to use.

func New

func New(opts ...Option) *Builder

New returns an empty Builder. Invalid options are reported by Build.

func (*Builder) Build added in v0.5.3

func (b *Builder) Build() (*Workflow, error)

Build validates the graph, freezes the Builder, and returns an immutable Workflow. Repeated calls return the same result.

func (*Builder) Job added in v0.5.3

func (b *Builder) Job(name string, job cron.Job, opts ...StepOption) Output[Unit]

Job adds a cron.Job step. Configuration errors are deferred to Build.

func (*Builder) MustBuild added in v0.5.3

func (b *Builder) MustBuild() *Workflow

MustBuild is Build with panic-on-error semantics.

func (*Builder) Step added in v0.5.3

func (b *Builder) Step[T any](
	name string,
	fn func(context.Context, Inputs) (T, error),
	opts ...StepOption,
) Output[T]

Step adds a typed function step. Configuration errors are deferred to Build.

type Condition

type Condition uint8

Condition selects the upstream result required by After.

const (
	OnSuccess Condition
	OnFailure
	OnSkipped
	OnComplete
)

type ConfigError

type ConfigError struct {
	Err  error
	Step string
	Dep  string
}

ConfigError identifies the step involved in an invalid graph.

func (*ConfigError) Error

func (e *ConfigError) Error() string

func (*ConfigError) Unwrap

func (e *ConfigError) Unwrap() error

type Execution

type Execution struct {
	ID        uuid.UUID
	StartedAt time.Time
	Duration  time.Duration
	// contains filtered or unexported fields
}

Execution reports one completed Workflow run.

func (*Execution) Err

func (e *Execution) Err() error

Err joins step errors in graph order.

func (*Execution) Error added in v0.5.3

func (e *Execution) Error(name string) error

Error returns the named step error.

func (*Execution) Errors

func (e *Execution) Errors() map[string]error

Errors returns a copy of non-nil step errors.

func (*Execution) Get added in v0.5.3

func (e *Execution) Get[T any](output Output[T]) (T, bool)

Get resolves a successful output from this execution.

func (*Execution) Result added in v0.5.3

func (e *Execution) Result(name string) (Result, bool)

Result returns the named result.

func (*Execution) Results

func (e *Execution) Results() map[string]Result

Results returns a copy of all results.

func (*Execution) Step added in v0.5.3

func (e *Execution) Step(name string) (StepReport, bool)

Step returns the named report.

func (*Execution) Steps added in v0.3.0

func (e *Execution) Steps() map[string]StepReport

Steps returns a copy of all reports.

type Inputs added in v0.3.0

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

Inputs exposes the successful outputs of a step's declared dependencies.

func (Inputs) Get added in v0.5.3

func (in Inputs) Get[T any](output Output[T]) (T, bool)

Get resolves a declared dependency with the exact output type.

type Option added in v0.5.3

type Option func(*builderConfig) error

Option configures a Builder.

func WithMaxParallelism added in v0.5.3

func WithMaxParallelism(limit int) Option

WithMaxParallelism limits simultaneously running steps. The default is 32.

type Output added in v0.5.3

type Output[T any] struct {
	// contains filtered or unexported fields
}

Output identifies one typed step output.

func (Output[T]) Name added in v0.5.3

func (o Output[T]) Name() string

Name returns the step name.

type Result

type Result uint8

Result is a step outcome.

const (
	ResultPending Result = iota
	ResultSuccess
	ResultFailure
	ResultSkipped
)

func (Result) String

func (r Result) String() string

type StepOption added in v0.5.3

type StepOption func(*step) error

StepOption configures one step.

func After

func After[T any](output Output[T], when Condition) StepOption

After declares an upstream dependency and its required result.

func WithRetry added in v0.5.3

func WithRetry(policy cron.RetryPolicy) StepOption

WithRetry applies a retry policy to one step.

func WithTimeout added in v0.5.3

func WithTimeout(timeout time.Duration) StepOption

WithTimeout caps one step run. Zero disables the timeout.

type StepReport added in v0.3.0

type StepReport struct {
	Result    Result
	Err       error
	StartedAt time.Time
	Duration  time.Duration
	// contains filtered or unexported fields
}

StepReport contains one step's outcome.

type Unit added in v0.5.3

type Unit struct{}

Unit is the output of a plain cron.Job step.

type Workflow

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

Workflow is an immutable DAG and implements cron.Job.

func (*Workflow) Execute added in v0.5.3

func (w *Workflow) Execute(ctx context.Context) *Execution

Execute runs the DAG once. At most the configured number of steps run at the same time.

func (*Workflow) Run

func (w *Workflow) Run(ctx context.Context) error

Run executes the DAG once and returns its joined error.

func (*Workflow) WithOnComplete

func (w *Workflow) WithOnComplete(cb func(*Execution)) *Workflow

WithOnComplete returns a copy that calls cb before Execute returns.

Jump to

Keyboard shortcuts

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