Skip to content

Commit 822699a

Browse files
committed
Change Nexus Link returned by handler to reference request ID
1 parent 9e0ee49 commit 822699a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

temporalnexus/operation.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import (
4343
"errors"
4444
"strings"
4545

46+
"github.com/google/uuid"
4647
"github.com/nexus-rpc/sdk-go/nexus"
4748
"go.temporal.io/api/common/v1"
48-
"go.temporal.io/api/enums/v1"
4949
"go.temporal.io/sdk/client"
5050
"go.temporal.io/sdk/internal"
5151
"go.temporal.io/sdk/internal/common/metrics"
@@ -280,6 +280,7 @@ type workflowHandle[T any] struct {
280280
id string
281281
runID string
282282
cachedToken string
283+
requestID string
283284
}
284285

285286
func (h workflowHandle[T]) ID() string {
@@ -291,14 +292,14 @@ func (h workflowHandle[T]) RunID() string {
291292
}
292293

293294
func (h workflowHandle[T]) link() nexus.Link {
294-
// Create the link information about the new workflow and return to the caller.
295+
// Create the link information about the workflow and return to the caller.
295296
link := &common.Link_WorkflowEvent{
296297
Namespace: h.namespace,
297298
WorkflowId: h.ID(),
298299
RunId: h.RunID(),
299-
Reference: &common.Link_WorkflowEvent_EventRef{
300-
EventRef: &common.Link_WorkflowEvent_EventReference{
301-
EventType: enums.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED,
300+
Reference: &common.Link_WorkflowEvent_RequestIdRef{
301+
RequestIdRef: &common.Link_WorkflowEvent_RequestIdReference{
302+
RequestId: h.requestID,
302303
},
303304
},
304305
}
@@ -350,9 +351,13 @@ func ExecuteUntypedWorkflow[R any](
350351
return nil, internal.ErrMissingWorkflowID
351352
}
352353

353-
if nexusOptions.RequestID != "" {
354-
internal.SetRequestIDOnStartWorkflowOptions(&startWorkflowOptions, nexusOptions.RequestID)
354+
requestID := nexusOptions.RequestID
355+
if requestID == "" {
356+
// Assigning a random UUID so the workflowHandle is able to create the link to the workflow.
357+
// Client.ExecuteWorkflow already does the same, so this is just assigning an UUID ahead.
358+
requestID = uuid.NewString()
355359
}
360+
internal.SetRequestIDOnStartWorkflowOptions(&startWorkflowOptions, requestID)
356361

357362
var encodedToken string
358363
if nexusOptions.CallbackURL != "" {
@@ -404,6 +409,7 @@ func ExecuteUntypedWorkflow[R any](
404409
id: run.GetID(),
405410
runID: run.GetRunID(),
406411
cachedToken: encodedToken,
412+
requestID: requestID,
407413
}, nil
408414
}
409415

test/nexus_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,10 @@ func TestAsyncOperationFromWorkflow(t *testing.T) {
878878
require.Equal(t, handlerWfID, link.GetWorkflowEvent().GetWorkflowId())
879879
require.NotEmpty(t, link.GetWorkflowEvent().GetRunId())
880880
require.True(t, proto.Equal(
881-
&common.Link_WorkflowEvent_EventReference{
882-
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED,
881+
&common.Link_WorkflowEvent_RequestIdReference{
882+
RequestId: handlerWfID,
883883
},
884-
link.GetWorkflowEvent().GetEventRef(),
884+
link.GetWorkflowEvent().GetRequestIdRef(),
885885
))
886886
handlerRunID := link.GetWorkflowEvent().GetRunId()
887887

0 commit comments

Comments
 (0)