kis-flow/flow/kis_flow_action.go

64 lines
1.3 KiB
Go
Raw Normal View History

2024-01-23 16:24:16 +08:00
package flow
import (
"context"
"errors"
"fmt"
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/kis"
2024-01-23 16:24:16 +08:00
)
// dealAction 处理Action决定接下来Flow的流程走向
func (flow *KisFlow) dealAction(ctx context.Context, fn kis.Function) (kis.Function, error) {
// DataReuse Action
if flow.action.DataReuse {
if err := flow.commitReuseData(ctx); err != nil {
return nil, err
}
} else {
if err := flow.commitCurData(ctx); err != nil {
return nil, err
}
}
// ForceEntryNext Action
if flow.action.ForceEntryNext {
if err := flow.commitVoidData(ctx); err != nil {
return nil, err
}
flow.abort = false
}
// JumpFunc Action
if flow.action.JumpFunc != "" {
if _, ok := flow.Funcs[flow.action.JumpFunc]; !ok {
//当前JumpFunc不在flow中
return nil, errors.New(fmt.Sprintf("Flow Jump -> %s is not in Flow", flow.action.JumpFunc))
}
jumpFunction := flow.Funcs[flow.action.JumpFunc]
// 更新上层Function
flow.PrevFunctionId = jumpFunction.GetPrevId()
fn = jumpFunction
// 如果设置跳跃,强制跳跃
flow.abort = false
} else {
// 更新上一层 FuncitonId 游标
flow.PrevFunctionId = flow.ThisFunctionId
fn = fn.Next()
}
// Abort Action 强制终止
if flow.action.Abort {
flow.abort = true
}
// 清空Action
flow.action = kis.Action{}
return fn, nil
}