feat: remove default timeout for both nodes and workflow (#585)
This commit is contained in:
@@ -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)
|
||||
counter := exeCtx.executed
|
||||
if counter == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
current := (*counter).Add(1)
|
||||
return current, current > maxNodeCountPerExecution
|
||||
}
|
||||
|
||||
func InitExecutedNodesCounter(ctx context.Context) context.Context {
|
||||
ctxcache.Store(ctx, executedNodeCountKey, atomic.Int64{})
|
||||
return ctx
|
||||
}
|
||||
|
||||
@@ -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,13 +163,16 @@ func restoreNodeCtx(ctx context.Context, nodeKey vo.NodeKey, resumeEvent *entity
|
||||
|
||||
currentC := GetExeCtx(ctx)
|
||||
|
||||
// restore the parent-child relationship between token collectors
|
||||
if storedCtx.TokenCollector != nil && storedCtx.TokenCollector.Parent != nil {
|
||||
currentTokenCollector := currentC.TokenCollector
|
||||
storedCtx.TokenCollector.Parent = currentTokenCollector
|
||||
}
|
||||
if currentC != nil {
|
||||
// restore the parent-child relationship between token collectors
|
||||
if storedCtx.TokenCollector != nil && storedCtx.TokenCollector.Parent != nil {
|
||||
currentTokenCollector := currentC.TokenCollector
|
||||
storedCtx.TokenCollector.Parent = currentTokenCollector
|
||||
}
|
||||
|
||||
storedCtx.AppVarStore = currentC.AppVarStore
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user