Skip to content

Commit d8a5c54

Browse files
committed
handle event type in request id reference link
1 parent 5c57638 commit d8a5c54

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

temporalnexus/link_converter.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const (
4545
urlPathTemplate = "/namespaces/%s/workflows/%s/%s/history"
4646

4747
linkWorkflowEventReferenceTypeKey = "referenceType"
48-
linkEventReferenceEventIDKey = "eventID"
49-
linkEventReferenceEventTypeKey = "eventType"
50-
linkEventReferenceRequestIDKey = "requestID"
48+
linkEventIDKey = "eventID"
49+
linkEventTypeKey = "eventType"
50+
linkRequestIDKey = "requestID"
5151
)
5252

5353
var (
@@ -142,7 +142,10 @@ func ConvertNexusLinkToLinkWorkflowEvent(link nexus.Link) (*commonpb.Link_Workfl
142142
EventRef: eventRef,
143143
}
144144
case requestIDReferenceType:
145-
requestIDRef := convertURLQueryToLinkWorkflowEventRequestIdReference(link.URL.Query())
145+
requestIDRef, err := convertURLQueryToLinkWorkflowEventRequestIdReference(link.URL.Query())
146+
if err != nil {
147+
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: %w", err)
148+
}
146149
we.Reference = &commonpb.Link_WorkflowEvent_RequestIdRef{
147150
RequestIdRef: requestIDRef,
148151
}
@@ -160,23 +163,23 @@ func convertLinkWorkflowEventEventReferenceToURLQuery(eventRef *commonpb.Link_Wo
160163
values := url.Values{}
161164
values.Set(linkWorkflowEventReferenceTypeKey, eventReferenceType)
162165
if eventRef.GetEventId() > 0 {
163-
values.Set(linkEventReferenceEventIDKey, strconv.FormatInt(eventRef.GetEventId(), 10))
166+
values.Set(linkEventIDKey, strconv.FormatInt(eventRef.GetEventId(), 10))
164167
}
165-
values.Set(linkEventReferenceEventTypeKey, enumspb.EventType_name[int32(eventRef.GetEventType())])
168+
values.Set(linkEventTypeKey, enumspb.EventType_name[int32(eventRef.GetEventType())])
166169
return values.Encode()
167170
}
168171

169172
func convertURLQueryToLinkWorkflowEventEventReference(queryValues url.Values) (*commonpb.Link_WorkflowEvent_EventReference, error) {
170173
var err error
171174
eventRef := &commonpb.Link_WorkflowEvent_EventReference{}
172-
eventIDValue := queryValues.Get(linkEventReferenceEventIDKey)
175+
eventIDValue := queryValues.Get(linkEventIDKey)
173176
if eventIDValue != "" {
174-
eventRef.EventId, err = strconv.ParseInt(queryValues.Get(linkEventReferenceEventIDKey), 10, 64)
177+
eventRef.EventId, err = strconv.ParseInt(queryValues.Get(linkEventIDKey), 10, 64)
175178
if err != nil {
176179
return nil, err
177180
}
178181
}
179-
eventRef.EventType, err = enumspb.EventTypeFromString(queryValues.Get(linkEventReferenceEventTypeKey))
182+
eventRef.EventType, err = enumspb.EventTypeFromString(queryValues.Get(linkEventTypeKey))
180183
if err != nil {
181184
return nil, err
182185
}
@@ -186,12 +189,19 @@ func convertURLQueryToLinkWorkflowEventEventReference(queryValues url.Values) (*
186189
func convertLinkWorkflowEventRequestIdReferenceToURLQuery(requestIDRef *commonpb.Link_WorkflowEvent_RequestIdReference) string {
187190
values := url.Values{}
188191
values.Set(linkWorkflowEventReferenceTypeKey, requestIDReferenceType)
189-
values.Set(linkEventReferenceRequestIDKey, requestIDRef.GetRequestId())
192+
values.Set(linkRequestIDKey, requestIDRef.GetRequestId())
193+
values.Set(linkEventTypeKey, enumspb.EventType_name[int32(requestIDRef.GetEventType())])
190194
return values.Encode()
191195
}
192196

193-
func convertURLQueryToLinkWorkflowEventRequestIdReference(queryValues url.Values) *commonpb.Link_WorkflowEvent_RequestIdReference {
194-
return &commonpb.Link_WorkflowEvent_RequestIdReference{
195-
RequestId: queryValues.Get(linkEventReferenceRequestIDKey),
197+
func convertURLQueryToLinkWorkflowEventRequestIdReference(queryValues url.Values) (*commonpb.Link_WorkflowEvent_RequestIdReference, error) {
198+
var err error
199+
requestIDRef := &commonpb.Link_WorkflowEvent_RequestIdReference{
200+
RequestId: queryValues.Get(linkRequestIDKey),
201+
}
202+
requestIDRef.EventType, err = enumspb.EventTypeFromString(queryValues.Get(linkEventTypeKey))
203+
if err != nil {
204+
return nil, err
196205
}
206+
return requestIDRef, nil
197207
}

temporalnexus/link_converter_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
149149
Reference: &commonpb.Link_WorkflowEvent_RequestIdRef{
150150
RequestIdRef: &commonpb.Link_WorkflowEvent_RequestIdReference{
151151
RequestId: "request-id",
152+
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED,
152153
},
153154
},
154155
},
@@ -157,11 +158,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
157158
Scheme: "temporal",
158159
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
159160
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
160-
RawQuery: "referenceType=RequestIdReference&requestID=request-id",
161+
RawQuery: "eventType=EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED&referenceType=RequestIdReference&requestID=request-id",
161162
},
162163
Type: "temporal.api.common.v1.Link.WorkflowEvent",
163164
},
164-
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?referenceType=RequestIdReference&requestID=request-id",
165+
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventType=EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED&referenceType=RequestIdReference&requestID=request-id",
165166
},
166167
{
167168
name: "valid request id empty",
@@ -180,11 +181,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
180181
Scheme: "temporal",
181182
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
182183
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
183-
RawQuery: "referenceType=RequestIdReference&requestID=",
184+
RawQuery: "eventType=EVENT_TYPE_UNSPECIFIED&referenceType=RequestIdReference&requestID=",
184185
},
185186
Type: "temporal.api.common.v1.Link.WorkflowEvent",
186187
},
187-
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?referenceType=RequestIdReference&requestID=",
188+
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventType=EVENT_TYPE_UNSPECIFIED&referenceType=RequestIdReference&requestID=",
188189
},
189190
}
190191

@@ -355,7 +356,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
355356
Scheme: "temporal",
356357
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
357358
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
358-
RawQuery: "referenceType=RequestIdReference&requestID=request-id",
359+
RawQuery: "referenceType=RequestIdReference&requestID=request-id&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED",
359360
},
360361
Type: "temporal.api.common.v1.Link.WorkflowEvent",
361362
},
@@ -366,6 +367,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
366367
Reference: &commonpb.Link_WorkflowEvent_RequestIdRef{
367368
RequestIdRef: &commonpb.Link_WorkflowEvent_RequestIdReference{
368369
RequestId: "request-id",
370+
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED,
369371
},
370372
},
371373
},
@@ -377,7 +379,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
377379
Scheme: "temporal",
378380
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
379381
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
380-
RawQuery: "referenceType=RequestIdReference&requestID=",
382+
RawQuery: "referenceType=RequestIdReference&requestID=&eventType=EVENT_TYPE_UNSPECIFIED",
381383
},
382384
Type: "temporal.api.common.v1.Link.WorkflowEvent",
383385
},
@@ -388,6 +390,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
388390
Reference: &commonpb.Link_WorkflowEvent_RequestIdRef{
389391
RequestIdRef: &commonpb.Link_WorkflowEvent_RequestIdReference{
390392
RequestId: "",
393+
EventType: enumspb.EVENT_TYPE_UNSPECIFIED,
391394
},
392395
},
393396
},

0 commit comments

Comments
 (0)