|
| 1 | +package api |
| 2 | + |
| 3 | +import ( |
| 4 | + commonpb "go.temporal.io/api/common/v1" |
| 5 | + enumspb "go.temporal.io/api/enums/v1" |
| 6 | + "go.temporal.io/server/common" |
| 7 | +) |
| 8 | + |
| 9 | +// GenerateStartedEventRefLink builds a Link pointing to the WORKFLOW_EXECUTION_STARTED event. |
| 10 | +// Use this for backlinks to workflow start: the started event is always EventId=1 (FirstEventID) |
| 11 | +// and is never buffered, so a concrete EventReference is appropriate. |
| 12 | +func GenerateStartedEventRefLink(namespace, workflowID, runID string) *commonpb.Link { |
| 13 | + return &commonpb.Link{ |
| 14 | + Variant: &commonpb.Link_WorkflowEvent_{ |
| 15 | + WorkflowEvent: &commonpb.Link_WorkflowEvent{ |
| 16 | + Namespace: namespace, |
| 17 | + WorkflowId: workflowID, |
| 18 | + RunId: runID, |
| 19 | + Reference: &commonpb.Link_WorkflowEvent_EventRef{ |
| 20 | + EventRef: &commonpb.Link_WorkflowEvent_EventReference{ |
| 21 | + EventId: common.FirstEventID, |
| 22 | + EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED, |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +// GenerateRequestIdRefLink builds a Link with a RequestIdReference. |
| 31 | +// Use this for events that are buffered at signal time (e.g. SIGNALED), where the |
| 32 | +// concrete EventId is not yet known. The server resolves the RequestId to a real |
| 33 | +// EventId once the buffer flushes. |
| 34 | +func GenerateRequestIdRefLink(namespace, workflowID, runID, requestID string, eventType enumspb.EventType) *commonpb.Link { |
| 35 | + return &commonpb.Link{ |
| 36 | + Variant: &commonpb.Link_WorkflowEvent_{ |
| 37 | + WorkflowEvent: &commonpb.Link_WorkflowEvent{ |
| 38 | + Namespace: namespace, |
| 39 | + WorkflowId: workflowID, |
| 40 | + RunId: runID, |
| 41 | + Reference: &commonpb.Link_WorkflowEvent_RequestIdRef{ |
| 42 | + RequestIdRef: &commonpb.Link_WorkflowEvent_RequestIdReference{ |
| 43 | + RequestId: requestID, |
| 44 | + EventType: eventType, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + } |
| 50 | +} |
0 commit comments