temporal
temporal copied to clipboard
Continue workflow as new and signal in a single transaction
I will be using Go SDK naming here. But I believe this is a server-side feature request.
Is your feature request related to a problem? Please describe.
It is possible to start a new workflow and send a signal to it in a signal transaction using SignalWithStartWorkflow
. However, it is not possible to continue a workflow as new (NewContinueAsNewError
) and send a signal to it in a single transaction.
A workflow example that demonstrates why this might be useful:
- The workflow is running "an infinite loop" by returning
NewContinueAsNewError
at the end of each execution. - During each iteration of this workflow it runs some activities given an input. This input can be updated while the workflow is running. The workflow will finish the current iteration using the old input. The updated input is used on the next iteration.
- In fact, the input can be updated multiple times during the single iteration. The next iteration must use the most recent input. All other input is considered stale and is discarded.
- The workflow sleeps at the end of each iteration if no new input was provided and starts the next iteration using the old input.
- If new input was provided while the workflow was running activities/during sleep, it skips sleep/stop sleeping and starts the next iteration using the new input right away.
This description suggests that it's best to provide input as a signal.
Pseudocode to implement this workflow:
- Start workflow/signal already running workflow using
SignalWithStartWorkflow
- Receive input signal
- Long running activities that use input
- Sleep unless new input is received:
4.1. No new input. Sleep until timer finishes. Return
NewContinueAsNewError
and signal old input in the same transaction. 4.2 New input was signalled (maybe several signals). Drain signal channel to get the most recently provided input. ReturnNewContinueAsNewError
and signal new input in a single transaction.
Describe the solution you'd like
Add new error type that is like NewContinueAsNewError
but allows signalling the new workflow in a single transaction like SignalWithStartWorkflow
.
Describe alternatives you've considered
Right now I wrote my workflow to accept the same input struct using both workflow function argument and signal. I need to accept input as signals because of the requirement to be able to update input for the next iteration while the current iteration is running. I need to be able to provide input as argument since this is currently the only way to provide input to the workflow that is started using NewContinueAsNewError
.
Providing the same input type using both workflow argument and signal is awkward, thus my feature request.
Additional context
In case my use case description and pseudocode don't make sense, here's the skeleton implementation of the workflow that I currently have: https://gist.github.com/mmxmb/d3a2b490855c98f0a28f3f6d30a005e2