Skip to content

Commit

Permalink
[temporal] adjust threshold for workflows to ContinueAsNew (#2328)
Browse files Browse the repository at this point in the history
Co-authored-by: Philip Dubé <[email protected]>
  • Loading branch information
heavycrystal and serprex authored Dec 17, 2024
1 parent 0d4d031 commit 02da43f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions flow/shared/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log/slog"

"go.temporal.io/sdk/client"
"go.temporal.io/sdk/workflow"

"github.com/PeerDB-io/peer-flow/generated/protos"
)
Expand All @@ -25,3 +26,9 @@ func GetWorkflowStatus(ctx context.Context, temporalClient client.Client, workfl
}
return state, nil
}

func ShouldWorkflowContinueAsNew(ctx workflow.Context) bool {
info := workflow.GetInfo(ctx)
return info.GetContinueAsNewSuggested() &&
(info.GetCurrentHistoryLength() > 40960 || info.GetCurrentHistorySize() > 40*1024*1024)
}
2 changes: 1 addition & 1 deletion flow/workflows/cdc_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func CDCFlowWorkflow(
return state, err
}

if workflow.GetInfo(ctx).GetContinueAsNewSuggested() {
if shared.ShouldWorkflowContinueAsNew(ctx) {
restart = true
if syncFlowFuture != nil {
if err := model.SyncStopSignal.SignalChildWorkflow(ctx, syncFlowFuture, struct{}{}).Get(ctx, nil); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion flow/workflows/sync_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func SyncFlowWorkflow(
}

if (options.NumberOfSyncs > 0 && currentSyncFlowNum >= options.NumberOfSyncs) ||
syncErr || ctx.Err() != nil || workflow.GetInfo(ctx).GetContinueAsNewSuggested() {
syncErr || ctx.Err() != nil || shared.ShouldWorkflowContinueAsNew(ctx) {
break
}
}
Expand Down

0 comments on commit 02da43f

Please sign in to comment.