Skip to content

Commit 4bc0d82

Browse files
committed
continue-as-new-suggested reason and signal
1 parent 2d05a73 commit 4bc0d82

File tree

6 files changed

+83
-6
lines changed

6 files changed

+83
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/nexus-rpc/sdk-go v0.3.0
1515
github.com/robfig/cron v1.2.0
1616
github.com/stretchr/testify v1.10.0
17-
go.temporal.io/api v1.53.0
17+
go.temporal.io/api v1.55.1-0.20251017163919-d527807d0d4e
1818
golang.org/x/sync v0.13.0
1919
golang.org/x/sys v0.32.0
2020
golang.org/x/time v0.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf
3535
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
3636
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
3737
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
38-
go.temporal.io/api v1.53.0 h1:6vAFpXaC584AIELa6pONV56MTpkm4Ha7gPWL2acNAjo=
39-
go.temporal.io/api v1.53.0/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
38+
go.temporal.io/api v1.55.1-0.20251017163919-d527807d0d4e h1:8Y8p3tBzobAYO3KjuoiGXjDxeKlPsrEjjDRfLlB7O7c=
39+
go.temporal.io/api v1.55.1-0.20251017163919-d527807d0d4e/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
4040
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4141
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
4242
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

internal/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const (
4040

4141
// QueryTypeWorkflowMetadata is the query name for the workflow metadata.
4242
QueryTypeWorkflowMetadata string = "__temporal_workflow_metadata"
43+
44+
// SignalTypeSuggestContinueAsNew is the signal name to set ContinueAsNewSuggested=true in the workflow env.
45+
SignalTypeSuggestContinueAsNew = "__suggest_continue_as_new"
4346
)
4447

4548
type (

internal/internal_event_handlers.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,9 @@ func (weh *workflowExecutionEventHandlerImpl) ProcessEvent(
11991199
// Update workflow info fields
12001200
weh.workflowInfo.currentHistoryLength = int(event.EventId)
12011201
weh.workflowInfo.continueAsNewSuggested = event.GetWorkflowTaskStartedEventAttributes().GetSuggestContinueAsNew()
1202+
weh.workflowInfo.continueAsNewSuggestedReason = convertContinueAsNewSuggestedReason(
1203+
event.GetWorkflowTaskStartedEventAttributes().GetContinueAsNewSuggestedReason(),
1204+
)
12021205
weh.workflowInfo.currentHistorySize = int(event.GetWorkflowTaskStartedEventAttributes().GetHistorySizeBytes())
12031206
// Reset the counter on command helper used for generating ID for commands
12041207
weh.commandsHelper.setCurrentWorkflowTaskStartedEventID(event.GetEventId())
@@ -1751,9 +1754,35 @@ func (weh *workflowExecutionEventHandlerImpl) ProcessLocalActivityResult(lar *lo
17511754
func (weh *workflowExecutionEventHandlerImpl) handleWorkflowExecutionSignaled(
17521755
attributes *historypb.WorkflowExecutionSignaledEventAttributes,
17531756
) error {
1757+
switch attributes.GetSignalName() {
1758+
case SignalTypeSuggestContinueAsNew:
1759+
weh.workflowInfo.continueAsNewSuggested = true
1760+
var reason enumspb.ContinueAsNewSuggestedReason
1761+
err := weh.dataConverter.FromPayload(attributes.GetInput().GetPayloads()[0], &reason)
1762+
if err != nil {
1763+
return fmt.Errorf("unable to convert continue-as-new suggested reason: %w", err)
1764+
}
1765+
weh.workflowInfo.continueAsNewSuggestedReason = convertContinueAsNewSuggestedReason(reason)
1766+
}
17541767
return weh.signalHandler(attributes.GetSignalName(), attributes.Input, attributes.Header)
17551768
}
17561769

1770+
// TODO(carlydf): move this helper somewhere appropriate
1771+
func convertContinueAsNewSuggestedReason(reason enumspb.ContinueAsNewSuggestedReason) ContinueAsNewSuggestedReason {
1772+
switch reason {
1773+
case enumspb.CONTINUE_AS_NEW_SUGGESTED_REASON_UNSPECIFIED:
1774+
return ContinueAsNewSuggestedReasonUnspecified
1775+
case enumspb.CONTINUE_AS_NEW_SUGGESTED_REASON_UPDATE_REGISTRY_TOO_LARGE:
1776+
return ContinueAsNewSuggestedReasonUpdateRegistryTooLarge
1777+
case enumspb.CONTINUE_AS_NEW_SUGGESTED_REASON_HISTORY_SIZE_TOO_LARGE:
1778+
return ContinueAsNewSuggestedReasonHistorySizeTooLarge
1779+
case enumspb.CONTINUE_AS_NEW_SUGGESTED_REASON_WORKER_DEPLOYMENT_VERSION_CHANGED:
1780+
return ContinueAsNewSuggestedReasonWorkerDeploymentVersionChanged
1781+
default:
1782+
return ContinueAsNewSuggestedReasonUnspecified
1783+
}
1784+
}
1785+
17571786
func (weh *workflowExecutionEventHandlerImpl) handleStartChildWorkflowExecutionFailed(event *historypb.HistoryEvent) error {
17581787
attributes := event.GetStartChildWorkflowExecutionFailedEventAttributes()
17591788
childWorkflowID := attributes.GetWorkflowId()

internal/workflow.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,39 @@ const (
6969
VersioningBehaviorAutoUpgrade
7070
)
7171

72+
// ContinueAsNewSuggestedReason specifies why ContinueAsNewSuggested is true.
73+
//
74+
// NOTE: Experimental
75+
//
76+
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewSuggestedReason]
77+
type ContinueAsNewSuggestedReason int
78+
79+
const (
80+
// ContinueAsNewSuggestedReasonUnspecified - ContinueAsNewSuggestedReason unknown.
81+
// Reason will be Unspecified if the server is not configured to suggest continue as new,
82+
// if the server is not configured to provide a reason for continue as new suggested, or
83+
// if continue as new is not suggested.
84+
//
85+
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewSuggestedReasonUnspecified]
86+
ContinueAsNewSuggestedReasonUnspecified ContinueAsNewSuggestedReason = iota
87+
88+
// ContinueAsNewSuggestedReasonHistorySizeTooLarge - Workflow History size is getting too large.
89+
//
90+
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewSuggestedReasonHistorySizeTooLarge]
91+
ContinueAsNewSuggestedReasonHistorySizeTooLarge
92+
93+
// ContinueAsNewSuggestedReasonUpdateRegistryTooLarge - Workflow Update registry is getting too large.
94+
//
95+
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewSuggestedReasonUpdateRegistryTooLarge]
96+
ContinueAsNewSuggestedReasonUpdateRegistryTooLarge
97+
98+
// ContinueAsNewSuggestedReasonWorkerDeploymentVersionChanged - Workflow's Worker Deployment has a new Ramping
99+
// Version or Current Version, and the workflow's Versioning Behavior is PinnedUntilContinueAsNew.
100+
//
101+
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewSuggestedReasonWorkerDeploymentVersionChanged]
102+
ContinueAsNewSuggestedReasonWorkerDeploymentVersionChanged
103+
)
104+
72105
// NexusOperationCancellationType specifies what action should be taken for a Nexus operation when the
73106
// caller is cancelled.
74107
//
@@ -1350,9 +1383,10 @@ type WorkflowInfo struct {
13501383
// this worker
13511384
currentTaskBuildID string
13521385

1353-
continueAsNewSuggested bool
1354-
currentHistorySize int
1355-
currentHistoryLength int
1386+
continueAsNewSuggested bool
1387+
continueAsNewSuggestedReason ContinueAsNewSuggestedReason
1388+
currentHistorySize int
1389+
currentHistoryLength int
13561390
// currentRunID is the current run ID of the workflow task, deterministic over reset
13571391
currentRunID string
13581392
}
@@ -1404,6 +1438,12 @@ func (wInfo *WorkflowInfo) GetContinueAsNewSuggested() bool {
14041438
return wInfo.continueAsNewSuggested
14051439
}
14061440

1441+
// GetContinueAsNewSuggestedReason returns the reason for ContinueAsNewSuggested if one exists.
1442+
// This value may change throughout the life of the workflow.
1443+
func (wInfo *WorkflowInfo) GetContinueAsNewSuggestedReason() ContinueAsNewSuggestedReason {
1444+
return wInfo.continueAsNewSuggestedReason
1445+
}
1446+
14071447
// GetWorkflowInfo extracts info of a current workflow from a context.
14081448
//
14091449
// Exposed as: [go.temporal.io/sdk/workflow.GetInfo]

workflow/deterministic_wrappers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ type (
5353
//
5454
// NOTE: Experimental
5555
AwaitOptions = internal.AwaitOptions
56+
57+
// ContinueAsNewSuggestedReason is the reason for ContinueAsNewSuggested
58+
//
59+
// NOTE: Experimental
60+
ContinueAsNewSuggestedReason = internal.ContinueAsNewSuggestedReason
5661
)
5762

5863
// Await blocks the calling thread until condition() returns true.

0 commit comments

Comments
 (0)