workflow

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveWorkflow

func SaveWorkflow(db *gorm.DB, w *Workflow) error

SaveWorkflow 保存工作流状态到数据库(gorm版本,如需自行保存可做参考)

Types

type Context

type Context struct {
	sync.Locker //锁

	Data     map[string]interface{} `json:"data"`     // 共享数据
	NodeID   string                 `json:"nodeID"`   // 当前节点ID
	Workflow *Workflow              `json:"workflow"` // 所属工作流
}

Context 工作流上下文

type DAG

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

DAG 有序无向图 提供方法:添加顶点,添加边,获取有向图

func NewDAG

func NewDAG() *DAG

func (*DAG) AddEdge

func (dag *DAG) AddEdge(from string, to string) error

AddEdge 添加边

func (*DAG) AddVertex

func (dag *DAG) AddVertex(id string, node interface{}) error

AddVertex 添加顶点

func (*DAG) TopologicalSort

func (dag *DAG) TopologicalSort() [][]string

TopologicalSort 有序拓扑图

type Node

type Node struct {
	ID          string                  `json:"ID"`          // 节点唯一标识
	Action      func(ctx Context) error `json:"-"`           // 执行函数
	RetryPolicy int                     `json:"RetryPolicy"` // 重试次数
	DependsOn   []string                `json:"DependsOn"`   // 依赖的节点ID
}

Node 工作流节点定义

type State

type State string

State 工作流状态类型

const (
	StatePending   State = "pending"
	StateRunning   State = "running"
	StateCompleted State = "completed"
	StateFailed    State = "failed"
)

type Workflow

type Workflow struct {
	ID    string          `json:"id"` //工作流唯一ID
	Nodes map[string]Node //节点集合
	State State           `json:"state"` //当前工作流状态

	Success map[string]bool `json:"success"`
	// contains filtered or unexported fields
}

Workflow 工作流定义

func LoadWorkflow

func LoadWorkflow(db *gorm.DB, id string) (*Workflow, error)

LoadWorkflow 从数据库恢复工作流(gorm版本,如需自行保存可做参考)

func (*Workflow) Resume

func (w *Workflow) Resume() error

Resume 从失败节点恢复

func (*Workflow) Run

func (w *Workflow) Run() error

Run 执行工作流(并发安全)

Jump to

Keyboard shortcuts

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