Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Nexus operation ID on callback headers #1710

Merged
merged 14 commits into from
Nov 27, 2024
10 changes: 10 additions & 0 deletions temporalnexus/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"context"
"errors"

"github.com/google/uuid"
"github.com/nexus-rpc/sdk-go/nexus"
"go.temporal.io/api/common/v1"
"go.temporal.io/api/enums/v1"
Expand Down Expand Up @@ -324,12 +325,21 @@
if startWorkflowOptions.TaskQueue == "" {
startWorkflowOptions.TaskQueue = nctx.TaskQueue
}
if startWorkflowOptions.ID == "" {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we want to require setting workflow ID for Nexus operations. We require it in all Core based SDKs, maybe we can at least protect Nexus users. Not blocking this PR though. @cretz, @Quinn-With-Two-Ns to weigh in on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the Go SDK did require setting a workflow ID for Nexus operations? I think it makes sense to require it or at least default it to something deterministic so starting a workflow is idempotent

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this was my intent but I think the client will automatically fill in an ID unless one is provided. Need to verify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We require it meaning I don't need the check for it being empty here? I looked for where a default would be set but didn't find anything that would set it before this point.

Copy link
Member

Choose a reason for hiding this comment

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

I would change to ensure that the client doesn't auto generate an ID if one isn't set.

We should note this change in the release notes. I would consider it a backwards incompatible behavior change.

	if startWorkflowOptions.ID == "" {
		return nil, ErrMissingWorkflowID
	}

Copy link
Member

Choose a reason for hiding this comment

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

@pdoerner this already changed for Java, please make sure to disallow empty workflow ID for nexus ops before merging this.

startWorkflowOptions.ID = uuid.NewString()
}

if nexusOptions.RequestID != "" {
internal.SetRequestIDOnStartWorkflowOptions(&startWorkflowOptions, nexusOptions.RequestID)
}

if nexusOptions.CallbackURL != "" {
if nexusOptions.CallbackHeader == nil {
nexusOptions.CallbackHeader = make(nexus.Header)
}
if _, set := nexusOptions.CallbackHeader[nexus.HeaderOperationID]; !set {

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest, stable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-intel, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-intel, stable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-arm, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-arm, stable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 340 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest, stable)

undefined: nexus.HeaderOperationID
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we use the case insensitive operations on the headers? I guess nexus.HeaderOperationID is now lower case so it isn't that important.

nexusOptions.CallbackHeader[nexus.HeaderOperationID] = startWorkflowOptions.ID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest, stable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-intel, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-intel, stable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-arm, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (macos-arm, stable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest, oldstable)

undefined: nexus.HeaderOperationID

Check failure on line 341 in temporalnexus/operation.go

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest, stable)

undefined: nexus.HeaderOperationID
}
internal.SetCallbacksOnStartWorkflowOptions(&startWorkflowOptions, []*common.Callback{
{
Variant: &common.Callback_Nexus_{
Expand Down
Loading