Skip to content

Commit

Permalink
[temporal] adjust threshold for workflows to ContinueAsNew
Browse files Browse the repository at this point in the history
  • Loading branch information
heavycrystal committed Dec 6, 2024
1 parent 8e87695 commit af25514
Show file tree
Hide file tree
Showing 3 changed files with 10 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)
}
3 changes: 2 additions & 1 deletion flow/workflows/cdc_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func CDCFlowWorkflow(
return state, err
}

if state.ActiveSignal == model.PauseSignal || workflow.GetInfo(ctx).GetContinueAsNewSuggested() {
if state.ActiveSignal == model.PauseSignal || shared.ShouldWorkflowContinueAsNew(ctx) {
restart = true
if syncFlowFuture != nil {
err := model.SyncStopSignal.SignalChildWorkflow(ctx, syncFlowFuture, struct{}{}).Get(ctx, nil)
Expand All @@ -620,6 +620,7 @@ func CDCFlowWorkflow(
}
}
}
workflow.GetInfo(ctx).GetCurrentHistorySize()

if restart {
if state.ActiveSignal == model.PauseSignal {
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 @@ -161,7 +161,7 @@ func SyncFlowWorkflow(
break
}

restart := syncErr || workflow.GetInfo(ctx).GetContinueAsNewSuggested()
restart := syncErr || shared.ShouldWorkflowContinueAsNew(ctx)
if !stop && !syncErr && mustWait {
waitSelector.Select(ctx)
if restart {
Expand Down

0 comments on commit af25514

Please sign in to comment.