NEXUS-474: Add sample for Workflow Update Nexus op#498
Conversation
|
|
||
| replace github.com/cactus/go-statsd-client => github.com/cactus/go-statsd-client/v5 v5.0.0 | ||
|
|
||
| replace go.temporal.io/sdk => ../sdk-go |
| ) | ||
|
|
||
| // Executes the UpdateWorkflow on the handler namespace's workflow via Nexus Operation | ||
| func UpdateRemoteCounterWorkflow(ctx workflow.Context, input api.Input) (api.Output, error) { |
There was a problem hiding this comment.
It is debatable, but I would lean towards the caller using a Standalone Nexus operation because it make the sample way simpler where you just need the start and the handler.
| options temporalnexus.StartTemporalOperationOptions, | ||
| ) (temporalnexus.TemporalOperationResult[api.Output], error) { | ||
| return temporalnexus.StartUpdateWorkflow[api.Output](ctx, nc, client.UpdateWorkflowOptions{ | ||
| WorkflowID: input.WorkflowID, |
There was a problem hiding this comment.
The SDK should require Update ID, like we require Workflow ID
There was a problem hiding this comment.
I was thinking about this and added the guard here
https://github.com/temporalio/sdk-go/pull/2417/changes#diff-a0e4841a913b018fa07362d309ee10c01435a802c443044b14d9aaa360c2146eR186
In regular UpdateWorkflow, an UpdateID is randomly generated if not supplied
This keeps the experience consistent - for an operation that does workflow update, use a random id - which happens to be the request ID- as update ID
If it retries due to a glitch, it will still be deterministic as the reqID is set on the nexusClient opts itself
And it keeps experience similar for the user as well whether theyre using workflow update within same ns or across
One thing im not 100% on is whether reqID itself can be empty - if yes, would need to add a check SDK side to generate random ID but remaining flow would be the same(set the updateID to requestID if empty)
| if err := workflow.SetUpdateHandler( | ||
| ctx, | ||
| api.IncrUpdateName, | ||
| func(ctx workflow.Context) (api.Output, error) { |
There was a problem hiding this comment.
NIT: I would show an input to the update handler so users see that a parameter can be passed through and how to do it. It is pretty trivial, but still good to show so users can more easily adapt this sample for their use case that will likely need a parameter. For this sample I would just pass through the amount you want to increase the counter.
What was changed
Added sample for Workflow Update Nexus op
Why?
Snippet to show usage
Checklist
Closes
How was this tested: