Skip to content

Commit

Permalink
DT-2502 - handle WorkflowExecutionUpdateAdmitted events (#2364)
Browse files Browse the repository at this point in the history
* handle WorkflowExecutionUpdateAdmitted events

this event type is only used on post-reset workflows when updates are reapplied,
but we still want to show their attributes in the event history

* fix dots and lines labels

* make initialEvent prop optional, remove comment

* optional
  • Loading branch information
rossedfort authored Oct 4, 2024
1 parent 78eb5d4 commit 11742db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/lib/models/event-groups/create-event-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ const createGroupFor = <K extends keyof StartingEvents>(
events?: CommonHistoryEvent[],
): EventGroup => {
const id = getGroupId(event);
const name = getEventGroupName(event);
const initialEvent = getInitialEvent(event, events);
const name = getEventGroupName(event, initialEvent);
const label = getEventGroupLabel(event);
const displayName = getEventGroupDisplayName(event);
const displayName = getEventGroupDisplayName(event, initialEvent);

const { timestamp, category, classification } = event;

const initialEvent = getInitialEvent(event, events);

const groupEvents: EventGroup['events'] = new Map();
const groupEventIds: EventGroup['eventIds'] = new Set();

Expand Down
22 changes: 17 additions & 5 deletions src/lib/models/event-groups/get-group-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import {
isTimerStartedEvent,
isWorkflowExecutionSignaledEvent,
isWorkflowExecutionUpdateAcceptedEvent,
isWorkflowExecutionUpdateAdmittedEvent,
} from '$lib/utilities/is-event-type';

export const getEventGroupName = (event: CommonHistoryEvent): string => {
export const getEventGroupName = (
event: CommonHistoryEvent,
initialEvent?: CommonHistoryEvent,
): string => {
if (!event) return '';

if (isActivityTaskScheduledEvent(event)) {
Expand Down Expand Up @@ -50,8 +54,13 @@ export const getEventGroupName = (event: CommonHistoryEvent): string => {
}

if (isWorkflowExecutionUpdateAcceptedEvent(event)) {
return event.workflowExecutionUpdateAcceptedEventAttributes?.acceptedRequest
?.input?.name;
if (isWorkflowExecutionUpdateAdmittedEvent(initialEvent)) {
return initialEvent.workflowExecutionUpdateAdmittedEventAttributes
?.request?.input?.name;
} else {
return event.workflowExecutionUpdateAcceptedEventAttributes
?.acceptedRequest?.input?.name;
}
}

if (isNexusOperationScheduledEvent(event)) {
Expand Down Expand Up @@ -102,12 +111,15 @@ export const getEventGroupLabel = (event: CommonHistoryEvent): string => {
}
};

export const getEventGroupDisplayName = (event: CommonHistoryEvent): string => {
export const getEventGroupDisplayName = (
event: CommonHistoryEvent,
initialEvent?: CommonHistoryEvent,
): string => {
if (!event) return '';

if (isLocalActivityMarkerEvent(event)) {
return getSummaryAttribute(event)?.value?.toString() ?? 'Local Activity';
}

return getEventGroupName(event);
return getEventGroupName(event, initialEvent);
};
2 changes: 2 additions & 0 deletions src/lib/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ export type ExternalWorkflowExecutionSignaledEvent =
EventWithAttributes<'externalWorkflowExecutionSignaledEventAttributes'>;
export type UpsertWorkflowSearchAttributesEvent =
EventWithAttributes<'upsertWorkflowSearchAttributesEventAttributes'>;
export type WorkflowExecutionUpdateAdmittedEvent =
EventWithAttributes<'workflowExecutionUpdateAdmittedEventAttributes'>;
export type WorkflowExecutionUpdateAcceptedEvent =
EventWithAttributes<'workflowExecutionUpdateAcceptedEventAttributes'>;
export type WorkflowExecutionUpdateCompletedEvent =
Expand Down
7 changes: 7 additions & 0 deletions src/lib/utilities/is-event-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import type {
WorkflowExecutionTerminatedEvent,
WorkflowExecutionTimedOutEvent,
WorkflowExecutionUpdateAcceptedEvent,
WorkflowExecutionUpdateAdmittedEvent,
WorkflowExecutionUpdateCompletedEvent,
WorkflowTaskCompletedEvent,
WorkflowTaskFailedEvent,
Expand Down Expand Up @@ -162,6 +163,7 @@ export const eventAttributeKeys: Readonly<EventAttributeKey[]> = [
'markerRecordedEventAttributes',
'workflowExecutionSignaledEventAttributes',
'workflowExecutionTerminatedEventAttributes',
'workflowExecutionUpdateAdmittedEventAttributes',
'workflowExecutionUpdateAcceptedEventAttributes',
'workflowExecutionUpdateCompletedEventAttributes',
'workflowExecutionUpdateRejectedEventAttributes',
Expand Down Expand Up @@ -453,6 +455,11 @@ export const isWorkflowExecutionUpdateAcceptedEvent =
'workflowExecutionUpdateAcceptedEventAttributes',
);

export const isWorkflowExecutionUpdateAdmittedEvent =
hasAttributes<WorkflowExecutionUpdateAdmittedEvent>(
'workflowExecutionUpdateAdmittedEventAttributes',
);

export const isWorkflowExecutionUpdateCompletedEvent =
hasAttributes<WorkflowExecutionUpdateCompletedEvent>(
'workflowExecutionUpdateCompletedEventAttributes',
Expand Down

0 comments on commit 11742db

Please sign in to comment.