feat: remove default timeout for both nodes and workflow (#585)
This commit is contained in:
parent
90b561c3df
commit
4b3042359c
|
|
@ -1552,7 +1552,6 @@ func (w *ApplicationService) OpenAPIRun(ctx context.Context, req *workflow.OpenA
|
|||
AgentID: agentID,
|
||||
ConnectorID: connectorID,
|
||||
ConnectorUID: strconv.FormatInt(userID, 10),
|
||||
TaskType: vo.TaskTypeForeground,
|
||||
InputFailFast: true,
|
||||
BizType: vo.BizTypeWorkflow,
|
||||
}
|
||||
|
|
@ -1563,6 +1562,7 @@ func (w *ApplicationService) OpenAPIRun(ctx context.Context, req *workflow.OpenA
|
|||
|
||||
if req.GetIsAsync() {
|
||||
exeCfg.SyncPattern = vo.SyncPatternAsync
|
||||
exeCfg.TaskType = vo.TaskTypeBackground
|
||||
exeID, err := GetWorkflowDomainSVC().AsyncExecute(ctx, exeCfg, parameters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -1575,6 +1575,7 @@ func (w *ApplicationService) OpenAPIRun(ctx context.Context, req *workflow.OpenA
|
|||
}
|
||||
|
||||
exeCfg.SyncPattern = vo.SyncPatternSync
|
||||
exeCfg.TaskType = vo.TaskTypeForeground
|
||||
wfExe, tPlan, err := GetWorkflowDomainSVC().SyncExecute(ctx, exeCfg, parameters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -268,7 +268,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-LLM-v2.jpg",
|
||||
SupportBatch: true,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 3 * 60 * 1000, // 3 minutes
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
InputSourceAware: true,
|
||||
|
|
@ -288,7 +287,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Plugin-v2.jpg",
|
||||
SupportBatch: true,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 3 * 60 * 1000, // 3 minutes
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -306,7 +304,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Code-v2.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
UseCtxCache: true,
|
||||
|
|
@ -325,7 +322,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-KnowledgeQuery-v2.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -371,7 +367,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Database-v2.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -425,7 +420,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Direct-Question-v2.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
MayUseChatModel: true,
|
||||
|
|
@ -473,7 +467,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
IsComposite: true,
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -491,7 +484,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Intent-v2.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
MayUseChatModel: true,
|
||||
|
|
@ -510,7 +502,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-KnowledgeWriting-v2.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -529,7 +520,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
IsComposite: true,
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -670,7 +660,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-update.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
},
|
||||
EnUSName: "Update Data",
|
||||
|
|
@ -687,7 +676,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icaon-database-select.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
},
|
||||
EnUSName: "Query Data",
|
||||
|
|
@ -704,7 +692,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-delete.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
},
|
||||
EnUSName: "Delete Data",
|
||||
|
|
@ -721,7 +708,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-HTTP.png",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
@ -739,7 +725,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-insert.jpg",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
},
|
||||
EnUSName: "Add Data",
|
||||
|
|
@ -780,8 +765,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
|
||||
// ExecutableMeta configures certain common aspects of request-time behaviors for this node.
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
// DefaultTimeoutMS configures the default timeout for this node, in milliseconds. 0 means no timeout.
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
// PreFillZero decides whether to pre-fill zero value for any missing fields in input.
|
||||
PreFillZero: true,
|
||||
// PostFillNil decides whether to post-fill nil value for any missing fields in output.
|
||||
|
|
@ -803,7 +786,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-from_json.png",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
UseCtxCache: true,
|
||||
|
|
@ -822,7 +804,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
|
|||
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icons-dataset-delete.png",
|
||||
SupportBatch: false,
|
||||
ExecutableMeta: ExecutableMeta{
|
||||
DefaultTimeoutMS: 60 * 1000, // 1 minute
|
||||
PreFillZero: true,
|
||||
PostFillNil: true,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -124,13 +124,15 @@ func newNodeRunConfig[O any](ns *schema2.NodeSchema,
|
|||
}, opts.init...)
|
||||
}
|
||||
|
||||
if execute.GetStaticConfig().MaxNodeCountPerExecution > 0 {
|
||||
opts.init = append(opts.init, func(ctx context.Context) (context.Context, error) {
|
||||
current, exceeded := execute.IncrAndCheckExecutedNodes(ctx)
|
||||
current, exceeded := execute.IncrementAndCheckExecutedNodes(ctx)
|
||||
if exceeded {
|
||||
return nil, fmt.Errorf("exceeded max executed node count: %d, current: %d", execute.GetStaticConfig().MaxNodeCountPerExecution, current)
|
||||
}
|
||||
return ctx, nil
|
||||
})
|
||||
}
|
||||
|
||||
return &nodeRunConfig[O]{
|
||||
nodeKey: ns.Key,
|
||||
|
|
@ -325,12 +327,23 @@ func (nc *nodeRunConfig[O]) invoke() func(ctx context.Context, input map[string]
|
|||
}()
|
||||
|
||||
for _, i := range runner.init {
|
||||
if ctx, err = i(ctx); err != nil {
|
||||
var newCtx context.Context
|
||||
if newCtx, err = i(ctx); err != nil {
|
||||
var err1 error
|
||||
if ctx, err1 = runner.onStart(ctx, input); err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
ctx = newCtx
|
||||
}
|
||||
}
|
||||
|
||||
if input, err = runner.preProcess(ctx, input); err != nil {
|
||||
var err1 error
|
||||
if ctx, err1 = runner.onStart(ctx, input); err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -373,12 +386,23 @@ func (nc *nodeRunConfig[O]) stream() func(ctx context.Context, input map[string]
|
|||
}()
|
||||
|
||||
for _, i := range runner.init {
|
||||
if ctx, err = i(ctx); err != nil {
|
||||
var newCtx context.Context
|
||||
if newCtx, err = i(ctx); err != nil {
|
||||
var err1 error
|
||||
if ctx, err1 = runner.onStart(ctx, input); err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
ctx = newCtx
|
||||
}
|
||||
}
|
||||
|
||||
if input, err = runner.preProcess(ctx, input); err != nil {
|
||||
var err1 error
|
||||
if ctx, err1 = runner.onStart(ctx, input); err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -390,6 +414,60 @@ func (nc *nodeRunConfig[O]) stream() func(ctx context.Context, input map[string]
|
|||
}
|
||||
}
|
||||
|
||||
func (nc *nodeRunConfig[O]) collect() func(ctx context.Context, input *schema.StreamReader[map[string]any], opts ...O) (output map[string]any, err error) {
|
||||
if nc.c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return func(ctx context.Context, input *schema.StreamReader[map[string]any], opts ...O) (output map[string]any, err error) {
|
||||
ctx, runner := newNodeRunner(ctx, nc)
|
||||
|
||||
defer func() {
|
||||
if panicErr := recover(); panicErr != nil {
|
||||
err = safego.NewPanicErr(panicErr, debug.Stack())
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
err = runner.onEnd(ctx, output)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
errOutput, hasErrOutput := runner.onError(ctx, err)
|
||||
if hasErrOutput {
|
||||
output = errOutput
|
||||
err = nil
|
||||
if output, err = runner.postProcess(ctx, output); err != nil {
|
||||
logs.CtxErrorf(ctx, "postProcess failed after returning error output: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for _, i := range runner.init {
|
||||
var newCtx context.Context
|
||||
if newCtx, err = i(ctx); err != nil {
|
||||
var err1 error
|
||||
if ctx, _, err1 = runner.onStartStream(ctx, input); err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
ctx = newCtx
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range runner.streamPreProcessors {
|
||||
input = p(ctx, input)
|
||||
}
|
||||
|
||||
if ctx, input, err = runner.onStartStream(ctx, input); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return runner.collect(ctx, input, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func (nc *nodeRunConfig[O]) transform() func(ctx context.Context, input *schema.StreamReader[map[string]any], opts ...O) (output *schema.StreamReader[map[string]any], err error) {
|
||||
if nc.t == nil {
|
||||
return nil
|
||||
|
|
@ -417,8 +495,15 @@ func (nc *nodeRunConfig[O]) transform() func(ctx context.Context, input *schema.
|
|||
}()
|
||||
|
||||
for _, i := range runner.init {
|
||||
if ctx, err = i(ctx); err != nil {
|
||||
var newCtx context.Context
|
||||
if newCtx, err = i(ctx); err != nil {
|
||||
var err1 error
|
||||
if ctx, _, err1 = runner.onStartStream(ctx, input); err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
ctx = newCtx
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +524,7 @@ func (nc *nodeRunConfig[O]) toNode() *Node {
|
|||
opts = append(opts, compose.WithLambdaType(string(nc.nodeType)))
|
||||
opts = append(opts, compose.WithLambdaCallbackEnable(true))
|
||||
|
||||
l, err := compose.AnyLambda(nc.invoke(), nc.stream(), nil, nc.transform(), opts...)
|
||||
l, err := compose.AnyLambda(nc.invoke(), nc.stream(), nc.collect(), nc.transform(), opts...)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create lambda for node %s, err: %v", nc.nodeName, err))
|
||||
}
|
||||
|
|
@ -589,6 +674,49 @@ func (r *nodeRunner[O]) stream(ctx context.Context, input map[string]any, opts .
|
|||
}
|
||||
}
|
||||
|
||||
func (r *nodeRunner[O]) collect(ctx context.Context, input *schema.StreamReader[map[string]any], opts ...O) (output map[string]any, err error) {
|
||||
if r.maxRetry == 0 {
|
||||
return r.c(ctx, input, opts...)
|
||||
}
|
||||
|
||||
copied := input.Copy(int(r.maxRetry))
|
||||
|
||||
var n int64
|
||||
defer func() {
|
||||
for i := n + 1; i < r.maxRetry; i++ {
|
||||
copied[i].Close()
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
default:
|
||||
}
|
||||
|
||||
output, err = r.c(ctx, copied[n], opts...)
|
||||
if err != nil {
|
||||
if _, ok := compose.IsInterruptRerunError(err); ok { // interrupt, won't retry
|
||||
r.interrupted = true
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logs.CtxErrorf(ctx, "[invoke] node %s ID %s failed on %d attempt, err: %v", r.nodeName, r.nodeKey, n, err)
|
||||
if r.maxRetry > n {
|
||||
n++
|
||||
if exeCtx := execute.GetExeCtx(ctx); exeCtx != nil && exeCtx.NodeCtx != nil {
|
||||
exeCtx.CurrentRetryCount++
|
||||
}
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return output, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *nodeRunner[O]) transform(ctx context.Context, input *schema.StreamReader[map[string]any], opts ...O) (output *schema.StreamReader[map[string]any], err error) {
|
||||
if r.maxRetry == 0 {
|
||||
return r.t(ctx, input, opts...)
|
||||
|
|
|
|||
|
|
@ -268,8 +268,6 @@ func (r *WorkflowRunner) Prepare(ctx context.Context) (
|
|||
}
|
||||
}
|
||||
|
||||
cancelCtx = execute.InitExecutedNodesCounter(cancelCtx)
|
||||
|
||||
lastEventChan := make(chan *execute.Event, 1)
|
||||
go func() {
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -18,17 +18,14 @@ package execute
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
|
||||
)
|
||||
|
||||
const (
|
||||
foregroundRunTimeout = 10 * time.Minute
|
||||
backgroundRunTimeout = 24 * time.Hour
|
||||
maxNodeCountPerWorkflow = 1000
|
||||
maxNodeCountPerExecution = 1000
|
||||
foregroundRunTimeout = 0 // timeout for workflow execution in foreground mode, 0 means no timeout
|
||||
backgroundRunTimeout = 0 // timeout for workflow execution in background mode, 0 means no timeout
|
||||
maxNodeCountPerWorkflow = 0 // maximum node count for a workflow, 0 means no limit
|
||||
maxNodeCountPerExecution = 0 // maximum node count for a workflow execution, 0 means no limit
|
||||
cancelCheckInterval = 200 * time.Millisecond
|
||||
)
|
||||
|
||||
|
|
@ -52,17 +49,17 @@ const (
|
|||
executedNodeCountKey = "executed_node_count"
|
||||
)
|
||||
|
||||
func IncrAndCheckExecutedNodes(ctx context.Context) (int64, bool) {
|
||||
counter, ok := ctxcache.Get[atomic.Int64](ctx, executedNodeCountKey)
|
||||
if !ok {
|
||||
func IncrementAndCheckExecutedNodes(ctx context.Context) (int64, bool) {
|
||||
exeCtx := GetExeCtx(ctx)
|
||||
if exeCtx == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
current := counter.Add(1)
|
||||
return current, current > maxNodeCountPerExecution
|
||||
counter := exeCtx.executed
|
||||
if counter == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func InitExecutedNodesCounter(ctx context.Context) context.Context {
|
||||
ctxcache.Store(ctx, executedNodeCountKey, atomic.Int64{})
|
||||
return ctx
|
||||
current := (*counter).Add(1)
|
||||
return current, current > maxNodeCountPerExecution
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/eino/compose"
|
||||
|
|
@ -30,6 +31,7 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
|
|
@ -48,6 +50,8 @@ type Context struct {
|
|||
CheckPointID string
|
||||
|
||||
AppVarStore *AppVariables
|
||||
|
||||
executed *atomic.Int64
|
||||
}
|
||||
|
||||
type RootCtx struct {
|
||||
|
|
@ -118,6 +122,7 @@ func restoreWorkflowCtx(ctx context.Context, h *WorkflowHandler) (context.Contex
|
|||
}
|
||||
|
||||
storedCtx.AppVarStore = currentC.AppVarStore
|
||||
storedCtx.executed = currentC.executed
|
||||
}
|
||||
|
||||
return context.WithValue(ctx, contextKey{}, storedCtx), nil
|
||||
|
|
@ -158,6 +163,7 @@ func restoreNodeCtx(ctx context.Context, nodeKey vo.NodeKey, resumeEvent *entity
|
|||
|
||||
currentC := GetExeCtx(ctx)
|
||||
|
||||
if currentC != nil {
|
||||
// restore the parent-child relationship between token collectors
|
||||
if storedCtx.TokenCollector != nil && storedCtx.TokenCollector.Parent != nil {
|
||||
currentTokenCollector := currentC.TokenCollector
|
||||
|
|
@ -165,6 +171,8 @@ func restoreNodeCtx(ctx context.Context, nodeKey vo.NodeKey, resumeEvent *entity
|
|||
}
|
||||
|
||||
storedCtx.AppVarStore = currentC.AppVarStore
|
||||
storedCtx.executed = currentC.executed
|
||||
}
|
||||
|
||||
storedCtx.NodeCtx.CurrentRetryCount = 0
|
||||
|
||||
|
|
@ -200,6 +208,9 @@ func tryRestoreNodeCtx(ctx context.Context, nodeKey vo.NodeKey) (context.Context
|
|||
if storedCtx.TokenCollector != nil && storedCtx.TokenCollector.Parent != nil && existingC != nil {
|
||||
currentTokenCollector := existingC.TokenCollector
|
||||
storedCtx.TokenCollector.Parent = currentTokenCollector
|
||||
|
||||
storedCtx.AppVarStore = existingC.AppVarStore
|
||||
storedCtx.executed = existingC.executed
|
||||
}
|
||||
|
||||
storedCtx.NodeCtx.CurrentRetryCount = 0
|
||||
|
|
@ -224,6 +235,7 @@ func PrepareRootExeCtx(ctx context.Context, h *WorkflowHandler) (context.Context
|
|||
TokenCollector: newTokenCollector(fmt.Sprintf("wf_%d", h.rootWorkflowBasic.ID), parentTokenCollector),
|
||||
StartTime: time.Now().UnixMilli(),
|
||||
AppVarStore: NewAppVariables(),
|
||||
executed: ptr.Of(atomic.Int64{}),
|
||||
}
|
||||
|
||||
if h.requireCheckpoint {
|
||||
|
|
@ -278,6 +290,7 @@ func PrepareSubExeCtx(ctx context.Context, wb *entity.WorkflowBasic, requireChec
|
|||
CheckPointID: newCheckpointID,
|
||||
StartTime: time.Now().UnixMilli(),
|
||||
AppVarStore: c.AppVarStore,
|
||||
executed: c.executed,
|
||||
}
|
||||
|
||||
if requireCheckpoint {
|
||||
|
|
@ -321,6 +334,7 @@ func PrepareNodeExeCtx(ctx context.Context, nodeKey vo.NodeKey, nodeName string,
|
|||
StartTime: time.Now().UnixMilli(),
|
||||
CheckPointID: c.CheckPointID,
|
||||
AppVarStore: c.AppVarStore,
|
||||
executed: c.executed,
|
||||
}
|
||||
|
||||
if c.NodeCtx == nil { // node within top level workflow, also not under composite node
|
||||
|
|
@ -368,6 +382,7 @@ func InheritExeCtxWithBatchInfo(ctx context.Context, index int, items map[string
|
|||
},
|
||||
CheckPointID: newCheckpointID,
|
||||
AppVarStore: c.AppVarStore,
|
||||
executed: c.executed,
|
||||
}), newCheckpointID
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue