Documentation ¶
Overview ¶
Package wfe provides a workflow engine.
This package allows you to define and execute workflows consisting of nodes and actions. You can create different types of flows, such as task flows and cron flows, and add nodes and actions to them. Actions can be defined using `ActionRunner` functions, and flows can be executed with a context and payload.
Example usage:
package main import ( "context" "fmt" "wfe" ) func main() { flow := wfe.New[string]("myFlow") flow.AddAction("hello", func(ctx context.Context, name string) error { fmt.Println("Hello,", name) return nil }) flow.AddNode(wfe.NewNode("helloNode", "hello")) if err := flow.Run(context.Background(), "World"); err != nil { fmt.Println("Error:", err) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action[P any] interface { // Run executes the action with the given context and payload. Run(ctx context.Context, p P) error Reference() string // ErrorRef returns the error reference of the action, if any. ErrorRef() *string }
Action is an interface representing an action in a workflow.
type ActionRunner ¶
ActionRunner is a function that runs an action with the given context and payload.
type Flow ¶
type Flow[P any] interface { Name() string Kind() Kind // AddNode adds one or more nodes to the flow. AddNode(n ...Node) // AddAction adds an action to the flow with the given reference, runner function, and optional error reference. AddAction(ref string, fn ActionRunner[P], errRef ...string) // GetAction retrieves an action from the flow by its reference. GetAction(ref string) (Action[P], bool) // Run executes the flow with the given context and payload. Run(ctx context.Context, p P) error // Cancel cancels the flow execution with the given context. Cancel(ctx context.Context) error }
Flow is an interface representing a workflow.
func NewWithCron ¶
NewWithCron creates a new cron flow with the given name and trigger.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.