Documentation
¶
Overview ¶
Package workflow 定义可编辑工作流、执行计划和生命周期协议。
Index ¶
Constants ¶
const ( MaxWorkflowIDLength = 100 MaxWorkflowNameLength = 100 MaxWorkflowDescriptionLength = 255 MaxWorkflowVersionLen = 50 MaxWorkflowRemarkLength = 255 MaxEnvironmentLength = 50 MaxWorkspaceLength = 100 MaxNodeIDLength = 100 MaxNodeNameLength = 100 MaxNodeTypeLength = 100 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NodeDefine ¶
type NodeDefine struct {
ID string `json:"id"`
Name string `json:"name"`
Kind NodeKind `json:"kind"`
Type string `json:"type,omitempty"`
Config RawConfig `json:"config,omitempty"`
Policy *NodePolicy `json:"policy,omitempty"`
Output *OutputDefine `json:"output,omitempty"`
Children []*NodeDefine `json:"children,omitempty"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
NodeDefine 是前端提交、控制面保存的可编辑协议形态。 runtime 只能在校验后直接执行它,或在 planner 转成 PlanNode 后执行。
func (NodeDefine) MarshalJSON ¶
func (n NodeDefine) MarshalJSON() ([]byte, error)
func (*NodeDefine) UnmarshalJSON ¶
func (n *NodeDefine) UnmarshalJSON(data []byte) error
type NodeKind ¶
type NodeKind string
NodeKind 是 workflow JSON 协议的一部分。 node 是叶子节点,其余 kind 是由 runtime 解释的结构容器。
const ( // NodeKindNode 通过 node.Registry 查找实际实现。 NodeKindNode NodeKind = "node" // NodeKindSerial 按 workflow JSON 中的 children 顺序执行。 NodeKindSerial NodeKind = "serial" // NodeKindParallel 隔离执行各分支,并在全部成功后按节点 ID 归档执行结果。 NodeKindParallel NodeKind = "parallel" // NodeKindCondition 根据 config.cases 选择一个分支。 NodeKindCondition NodeKind = "condition" )
type NodeOnError ¶
type NodeOnError string
NodeOnError 定义节点最终失败后的 runtime 处理方式。
const ( // NodeOnErrorFail 表示节点失败后 workflow 返回失败。 NodeOnErrorFail NodeOnError = "fail" // NodeOnErrorSkip 表示节点失败后标记 skipped,并继续后续可执行节点。 NodeOnErrorSkip NodeOnError = "skip" )
type NodePolicy ¶
type NodePolicy struct {
TimeoutMs *int `json:"timeoutMs,omitempty"`
OnError NodeOnError `json:"onError,omitempty"`
Retry *RetryPolicy `json:"retry,omitempty"`
}
NodePolicy 是框架拥有的节点执行策略,放在 node.policy 中。 它和节点业务 Config 分开,避免 HTTP、gRPC 等节点自己的参数和框架控制参数混在一起。
func CloneNodePolicy ¶
func CloneNodePolicy(src *NodePolicy) *NodePolicy
CloneNodePolicy 深拷贝节点策略,避免 planner/runtime 修改共享指针。
type NodeStatus ¶
type NodeStatus string
NodeStatus 表示节点在一次执行或调试展示中的生命周期状态。
const ( // NodeStatusPending 表示节点尚未开始,主要用于前端状态建模。 NodeStatusPending NodeStatus = "pending" // NodeStatusRunning 表示节点正在执行。 NodeStatusRunning NodeStatus = "running" // NodeStatusSucceeded 表示节点执行成功。 NodeStatusSucceeded NodeStatus = "succeeded" // NodeStatusFailed 表示节点执行失败。 NodeStatusFailed NodeStatus = "failed" // NodeStatusSkipped 表示节点被禁用或按策略跳过。 NodeStatusSkipped NodeStatus = "skipped" // NodeStatusTimeout 表示节点执行超时。 NodeStatusTimeout NodeStatus = "timeout" // NodeStatusRetrying 表示节点失败后仍在重试周期内。 NodeStatusRetrying NodeStatus = "retrying" // NodeStatusCanceled 表示上游 context 取消导致节点停止。 NodeStatusCanceled NodeStatus = "canceled" )
type OutputDefine ¶
type OutputDefine struct {
Namespace string `json:"namespace,omitempty"`
Merge *bool `json:"merge,omitempty"`
Mappings map[string]string `json:"mappings,omitempty"`
}
OutputDefine 控制节点输出如何写回共享 FlowContext。 节点可以直接返回 map/普通值,也可以返回 NodeResult 表达业务拒绝。
type Plan ¶
type Plan struct {
Workflow *Workflow `json:"workflow"`
Root *PlanNode `json:"root"`
Nodes map[string]*PlanNode `json:"-"`
BuiltAt time.Time `json:"builtAt"`
NodeCount int `json:"nodeCount"`
}
Plan 是 Workflow 面向 runtime 的执行形态。 它保留原始 workflow 身份和版本信息,同时补充节点索引、路径和父子坐标, 让执行、trace、调试展示不必反复推导树关系。
type PlanNode ¶
type PlanNode struct {
ID string `json:"id"`
Name string `json:"name"`
Kind NodeKind `json:"kind"`
Type string `json:"type,omitempty"`
Config RawConfig `json:"config,omitempty"`
Policy *NodePolicy `json:"policy,omitempty"`
Output *OutputDefine `json:"output,omitempty"`
Children []*PlanNode `json:"children,omitempty"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
ParentID string `json:"parentId,omitempty"`
Depth int `json:"depth"`
Index int `json:"index"`
Path string `json:"path"`
}
PlanNode 刻意保留 NodeDefine 的业务字段,因为 runtime 仍需要同一份节点配置。 ParentID、Depth、Index、Path 由 planner 生成,不应回写成用户可编辑的 workflow 定义。
func (*PlanNode) IsContainer ¶
func (*PlanNode) ToNodeDefine ¶
func (n *PlanNode) ToNodeDefine() *NodeDefine
ToNodeDefine 会丢弃 planner 生成的坐标信息,用于跨越只接受可编辑 workflow JSON 的边界。
type RawConfig ¶
type RawConfig map[string]interface{}
RawConfig 是节点业务配置的原始 JSON 对象。 框架只要求它是 JSON object;具体字段由前端配置构建器和后端节点实现约定。
type RetryPolicy ¶
type RetryPolicy struct {
MaxAttempts *int `json:"maxAttempts,omitempty"`
DelayMs *int `json:"delayMs,omitempty"`
}
RetryPolicy 描述 node 节点失败后的重试次数和重试间隔。
type ReturningConfig ¶
type ReturningConfig struct {
Params *bool `json:"params,omitempty"`
Vars *bool `json:"vars,omitempty"`
Results *bool `json:"results,omitempty"`
Response *bool `json:"response,omitempty"`
Envelope *bool `json:"envelope,omitempty"`
Workflow *bool `json:"workflow,omitempty"`
Nodes *bool `json:"nodes,omitempty"`
Environment *bool `json:"environment,omitempty"`
Trace *bool `json:"trace,omitempty"`
}
ReturningConfig 控制 WorkflowResult.Output 中包含哪些 FlowContext 区块。
未配置时 runtime 返回常用 ctx 快照:params、vars、results、response、envelope。 trace 可能较重,必须显式开启。
func (*ReturningConfig) Enabled ¶
func (c *ReturningConfig) Enabled(section ReturningSection, defaultValue bool) bool
Enabled 判断某个 output 区块是否应该返回。
type ReturningSection ¶
type ReturningSection string
ReturningSection 是 WorkflowResult.Output 中可被 workflow.returning 控制的区块。
const ( ReturningSectionParams ReturningSection = "params" ReturningSectionVars ReturningSection = "vars" ReturningSectionResults ReturningSection = "results" ReturningSectionResponse ReturningSection = "response" ReturningSectionEnvelope ReturningSection = "envelope" ReturningSectionWorkflow ReturningSection = "workflow" ReturningSectionNodes ReturningSection = "nodes" ReturningSectionEnvironment ReturningSection = "environment" ReturningSectionTrace ReturningSection = "trace" )
type SwitchBinding ¶
type SwitchBinding struct {
SwitchName string `json:"switchName"`
}
SwitchBinding 保存一个 FlowLink 开关由外部 Switch 功能开关控制时的引用。
type TracingConfig ¶
type TracingConfig struct {
Enabled *bool `json:"enabled,omitempty"`
SwitchBinding *SwitchBinding `json:"switchBinding,omitempty"`
}
TracingConfig 统一控制一次 workflow 执行的事件、节点日志和统计。 持久化不在这里配置;是否导出到具体 sink 由链路中的 collector 节点决定。
func CloneTracingConfig ¶
func CloneTracingConfig(src *TracingConfig) *TracingConfig
CloneTracingConfig 深拷贝 tracing 配置,供 plan 层生成单次执行快照。
func (*TracingConfig) UnmarshalJSON ¶
func (c *TracingConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON 把旧版 events/logs/stats 三开关配置归一化为单一追踪开关。
type Workflow ¶
type Workflow struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Revision uint64 `json:"revision,omitempty"`
Env string `json:"env"`
Workspace string `json:"workspace"`
Service string `json:"service"`
Description string `json:"description"`
Tracing *TracingConfig `json:"tracing,omitempty"`
Returning *ReturningConfig `json:"returning,omitempty"`
Root *NodeDefine `json:"root"`
}
Workflow 是前端编排、后端保存、runtime 执行的原始链路定义。 它描述“用户想怎么编排”,不携带 planner 生成的父子路径、深度、索引等执行期辅助信息。
func (Workflow) MarshalJSON ¶
func (*Workflow) UnmarshalJSON ¶
type WorkflowStatus ¶
type WorkflowStatus string
WorkflowStatus 表示 workflow 版本在控制面的生命周期状态。
const ( // WorkflowStatusUnpublished 表示尚未发布的普通版本,可以继续编辑,但不能被 worker 拉取执行。 WorkflowStatusUnpublished WorkflowStatus = "unpublished" // WorkflowStatusPublished 表示已发布版本,可被业务 worker 拉取执行。 WorkflowStatusPublished WorkflowStatus = "published" // WorkflowStatusDisabled 表示已停用版本,不再作为正常执行目标。 WorkflowStatusDisabled WorkflowStatus = "disabled" )
type WorkflowVersion ¶
type WorkflowVersion struct {
ID string `json:"id"`
WorkflowID string `json:"workflowId"`
Env string `json:"env"`
Workspace string `json:"workspace"`
Service string `json:"service"`
Version string `json:"version"`
Revision uint64 `json:"revision"`
Status WorkflowStatus `json:"status"`
Definition *Workflow `json:"definition"`
PublishedBy string `json:"publishedBy"`
PublishedAt time.Time `json:"publishedAt"`
UpdatedAt time.Time `json:"updatedAt"`
Remark string `json:"remark"`
}
WorkflowVersion 是控制面保存和查询 workflow 版本时使用的记录。 Definition 保存对应版本的完整 Workflow JSON;发布信息记录谁在什么时候发布了该版本。
func (WorkflowVersion) MarshalJSON ¶ added in v0.2.0
func (v WorkflowVersion) MarshalJSON() ([]byte, error)
func (*WorkflowVersion) UnmarshalJSON ¶ added in v0.2.0
func (v *WorkflowVersion) UnmarshalJSON(data []byte) error