kis-flow/flow/kis_flow_action.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

2024-01-23 16:24:16 +08:00
package flow
import (
"context"
"errors"
"fmt"
2024-04-15 18:18:40 +08:00
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/kis"
2024-01-23 16:24:16 +08:00
)
2024-04-15 17:50:02 +08:00
// dealAction handles Action to determine the next direction of the Flow.
2024-01-23 16:24:16 +08:00
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 {
2024-04-15 17:50:02 +08:00
// The current JumpFunc is not in the flow
2024-01-23 16:24:16 +08:00
return nil, errors.New(fmt.Sprintf("Flow Jump -> %s is not in Flow", flow.action.JumpFunc))
}
jumpFunction := flow.Funcs[flow.action.JumpFunc]
2024-04-15 17:50:02 +08:00
// Update the upper layer Function
2024-01-23 16:24:16 +08:00
flow.PrevFunctionId = jumpFunction.GetPrevId()
fn = jumpFunction
2024-04-15 17:50:02 +08:00
// If set to jump, force the jump
2024-01-23 16:24:16 +08:00
flow.abort = false
} else {
2024-04-15 17:50:02 +08:00
// Update the upper layer FunctionId cursor
2024-01-23 16:24:16 +08:00
flow.PrevFunctionId = flow.ThisFunctionId
fn = fn.Next()
}
2024-04-15 17:50:02 +08:00
// Abort Action force termination
2024-01-23 16:24:16 +08:00
if flow.action.Abort {
flow.abort = true
}
2024-04-15 17:50:02 +08:00
// Clear Action
2024-01-23 16:24:16 +08:00
flow.action = kis.Action{}
return fn, nil
}