Skip to content

NEXUS-474: Add sample for Workflow Update Nexus op#498

Draft
mavemuri wants to merge 2 commits into
mainfrom
mavemuri/update-nexus-op
Draft

NEXUS-474: Add sample for Workflow Update Nexus op#498
mavemuri wants to merge 2 commits into
mainfrom
mavemuri/update-nexus-op

Conversation

@mavemuri

Copy link
Copy Markdown

What was changed

Added sample for Workflow Update Nexus op

Why?

Snippet to show usage

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?
  • [ ]

Comment thread go.mod

replace github.com/cactus/go-statsd-client => github.com/cactus/go-statsd-client/v5 v5.0.0

replace go.temporal.io/sdk => ../sdk-go

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

// Executes the UpdateWorkflow on the handler namespace's workflow via Nexus Operation
func UpdateRemoteCounterWorkflow(ctx workflow.Context, input api.Input) (api.Output, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - ill add both!

options temporalnexus.StartTemporalOperationOptions,
) (temporalnexus.TemporalOperationResult[api.Output], error) {
return temporalnexus.StartUpdateWorkflow[api.Output](ctx, nc, client.UpdateWorkflowOptions{
WorkflowID: input.WorkflowID,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK should require Update ID, like we require Workflow ID

@mavemuri mavemuri Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants