sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

Workflow API to check if ContinueAsNew is required

Open rylandg opened this issue 3 years ago • 2 comments

When writing infinitely running Workflows, handling ContinueAsNew becomes an immediate requirement in the design. For applications that have multiple infinitely running Workflow types, managing the correct ContinueAsNew timing/behavior becomes tedious and frustrating.

To solve this problem, I personally resorted to wrapping the Workflow API in a struct. This essentially functions as an unofficial interceptor and maintains a counter of "actions" (transitions basically) by incrementing the count each time a stateful API is called (ExecuteActivity, SignalWorkflow etc). Then each infinitely running Workflow is required to regularly check the counter and see if its exceeded the safe threshold. If it has, we then ContinueAsNew.

It would be ideal if this was provided out of the box. Ideally on the Client it would be possible to specify the safe limits for a given Workflow type such that the API can be dynamically configured for each specific case. At minimum it would be great to know the number of events and history size for a Workflow.

rylandg avatar Nov 11 '21 21:11 rylandg

This was already requested for TS https://github.com/temporalio/sdk-typescript/issues/357. Once we implement it there we'll port to the other SDKs.

bergundy avatar Nov 11 '21 22:11 bergundy

The history size is now available in WorkflowInfo protobuf so this should be easy to add.

robholland avatar Jan 29 '22 20:01 robholland