The chain package provides a flexible framework for building and executing sequential workflows (pipelines) of actions. It allows you to define a series of steps, each represented by an Action, which processes inputs and produces outputs. The package supports conditional branching, customizable execution paths, and error handling, enabling complex workflows with minimal boilerplate.
-
Action and Pipeline Composition
Create modular, reusable units of work (Action
) and orchestrate them into robust workflows usingPipeline
. -
DAG-based Execution Plans
Ensure predictable execution and robust validation with built-in cycle detection to enforce acyclic workflows. -
Nested Pipelines
Use pipelines as actions within other pipelines, enabling modular and hierarchical workflow designs. -
Conditional Branching
Support forSuccess
,Failure
,Abort
and custom direction-based branching within your execution flows. -
AggregateAction Support
Simplify the orchestration of complex workflows by combiningAction
s orPipeline
s of different types into a unified control flow using AggregateAction.
To install the chain package, use the following command:
go get github.com/JSYoo5B/chain
An Action
represents a single task in the pipeline. Each action can process input data and return output or an error.
type Action[T any] interface {
Name() string
Run(ctx context.Context, input T) (output T, err error)
}
A BranchAction
extends Action
and supports conditional branching. It can change the execution flow based on the results of the action, allowing for multiple execution paths.
type BranchAction[T any] interface {
Name() string
Run(ctx context.Context, input T) (output T, err error)
Directions() []string
NextDirection(ctx context.Context, output T) (direction string, err error)
}
A Pipeline
is a sequence of Action
s executed in order. It orchestrates the flow of data between actions and handles branching, success, error, and abort conditions.
An ActionPlan
is a map that associates a direction (e.g., success, error, abort) with the next Action to execute, defining the flow of a pipeline.
type ActionPlan[T any] map[string]Action[T]
Practical examples for using the chain
package will be added in future updates. Stay tuned!