workflow

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ErrorHandler is handler called when a workflow experiences an error. The error may originate
	// from hook or from a task. The original error is alwasy returned from the workflow's Execute.
	// Optional. Defaults to a no-op handler.
	ErrorHandler ErrorHandler
}

Config is the configuration for constructing a Workflow instance.

type ErrDuplicateTaskName

type ErrDuplicateTaskName struct {
	Name TaskName
}

ErrDuplicateTaskName indicates 2 tasks with the same TaskName have been added to a workflow.

func (ErrDuplicateTaskName) Error

func (e ErrDuplicateTaskName) Error() string

type ErrorHandler

type ErrorHandler func(context.Context, error)

ErrorHandler is a function called when a workflow experiences an error during execution. The error may originate from hook execution or from a task.

type HookBinder

type HookBinder interface {
	// BindPreWorkflowHook binds a task to a workflow that is run _before_ a workflow is executed.
	BindPreWorkflowHook(Task)

	// BindPostWorkflowHook binds a task to a workflow that is run _after_ a workflow is executed.
	BindPostWorkflowHook(Task)

	// BindPreTaskHook binds task to be run _before_ the anchor task is executed.
	BindPreTaskHook(anchor TaskName, task Task)

	// BindPostTaskHook binds Task to be run _after_ the anchor task is executed.
	BindPostTaskHook(anchor TaskName, task Task)
}

HookBinder is used by hook registrars to bind tasks to be executed among the workflow's core task set.

type Task

type Task interface {
	// RunTask executes the task. Tasks may return a context that should be used in subsequent task
	// execution.
	RunTask(context.Context) (context.Context, error)
}

Task represents an individual step within a workflow that can be run.

type TaskFunc added in v0.13.0

type TaskFunc func(context.Context) (context.Context, error)

TaskFunc is a helper for defining inline tasks. It is used by type converting a function to TaskFunc.

Example:

workflow.TaskFunc(func(ctx context.Context) (context.Context, error) {
	return ctx, nil
})

func (TaskFunc) RunTask added in v0.13.0

func (fn TaskFunc) RunTask(ctx context.Context) (context.Context, error)

RunTask satisfies the Task interface.

type TaskName

type TaskName string

TaskName uniquely identifies a task within a given workflow.

type Workflow

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

Workflow defines an abstract workflow that can execute a serialized set of tasks.

func New

func New(cfg Config) *Workflow

New initializes a Workflow instance without any tasks or hooks.

func (*Workflow) AppendTask

func (w *Workflow) AppendTask(name TaskName, t Task) error

AppendTask appends t to the list of workflow tasks. Task names must be unique within a workflow. Duplicate names will receive an ErrDuplicateTaskName.

func (*Workflow) BindPostTaskHook

func (w *Workflow) BindPostTaskHook(id TaskName, t Task)

BindPostHook implements the HookBinder interface.

func (*Workflow) BindPostWorkflowHook

func (w *Workflow) BindPostWorkflowHook(t Task)

BindPostWorkflowHook implements the HookBinder interface.

func (*Workflow) BindPreTaskHook

func (w *Workflow) BindPreTaskHook(id TaskName, t Task)

BindPreTaskHook implements the HookBinder interface.

func (*Workflow) BindPreWorkflowHook

func (w *Workflow) BindPreWorkflowHook(t Task)

BindPreWorkflowHook implements the HookBinder interface.

func (*Workflow) Execute

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

Execute executes the workflow running any pre and post hooks registered for each task.

Directories

Path Synopsis
task
Package workflowcontext contains utility functions for populating workflow context specific data in a context.Context.
Package workflowcontext contains utility functions for populating workflow context specific data in a context.Context.

Jump to

Keyboard shortcuts

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