Skip to content

Commit bcdcdc8

Browse files
Fix pending decisions (#852)
* Fix pending decisions * change label to start * fix snapshot * Update src/views/workflow-history/helpers/pending-decision-info-to-event.ts * Update src/utils/data-formatters/format-pending-workflow-history-event/format-pending-decision-start-event.ts --------- Co-authored-by: Adhitya Mamallan <[email protected]>
1 parent 485d061 commit bcdcdc8

23 files changed

+263
-217
lines changed

src/utils/data-formatters/format-pending-workflow-history-event/__tests__/index.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { ZodError } from 'zod';
33
import logger from '@/utils/logger';
44
import {
55
pendingActivityTaskStartEvent,
6-
pendingActivityTaskStartEventWithScheduledState,
7-
pendingDecisionTaskScheduleEvent,
6+
pendingActivityTaskStartEventWithStartedState,
7+
pendingDecisionTaskStartEvent,
8+
pendingDecisionTaskStartEventWithStartedState,
89
} from '@/views/workflow-history/__fixtures__/workflow-history-pending-events';
910

1011
import formatPendingWorkflowHistoryEvent from '..';
@@ -13,8 +14,9 @@ jest.mock('@/utils/logger');
1314

1415
const pendingEvents = [
1516
pendingActivityTaskStartEvent,
16-
pendingActivityTaskStartEventWithScheduledState,
17-
pendingDecisionTaskScheduleEvent,
17+
pendingActivityTaskStartEventWithStartedState,
18+
pendingDecisionTaskStartEvent,
19+
pendingDecisionTaskStartEventWithStartedState,
1820
];
1921
describe('formatWorkflowHistoryEvent', () => {
2022
pendingEvents.forEach((event) => {

src/utils/data-formatters/format-pending-workflow-history-event/__tests__/index.test.ts.snapshot

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ exports[`formatWorkflowHistoryEvent should format workflow pendingActivityTaskSt
77
"name": "activity.cron.Start",
88
},
99
"attempt": 1,
10-
"eventId": null,
1110
"eventTime": 2024-09-07T22:16:10.599Z,
1211
"eventType": "PendingActivityTaskStart",
1312
"expirationTime": 1970-01-01T00:06:00.000Z,
@@ -24,8 +23,8 @@ exports[`formatWorkflowHistoryEvent should format workflow pendingActivityTaskSt
2423
"maximumAttempts": 10,
2524
"scheduleId": 7,
2625
"scheduledTime": 1970-01-01T00:03:00.000Z,
27-
"startedWorkerIdentity": "",
28-
"state": "started",
26+
"startedWorkerIdentity": "worker-1",
27+
"state": "scheduled",
2928
}
3029
`;
3130

@@ -36,7 +35,6 @@ exports[`formatWorkflowHistoryEvent should format workflow pendingActivityTaskSt
3635
"name": "activity.cron.Start",
3736
},
3837
"attempt": 1,
39-
"eventId": null,
4038
"eventTime": 2024-09-07T22:16:10.599Z,
4139
"eventType": "PendingActivityTaskStart",
4240
"expirationTime": 1970-01-01T00:06:00.000Z,
@@ -48,25 +46,38 @@ exports[`formatWorkflowHistoryEvent should format workflow pendingActivityTaskSt
4846
"lastFailureDetails": null,
4947
"lastFailureReason": "",
5048
"lastHeartbeatTime": null,
51-
"lastStartedTime": null,
49+
"lastStartedTime": 2024-09-07T22:16:10.599Z,
5250
"lastWorkerIdentity": "",
5351
"maximumAttempts": 10,
5452
"scheduleId": 7,
5553
"scheduledTime": 1970-01-01T00:03:00.000Z,
56-
"startedWorkerIdentity": "",
57-
"state": "scheduled",
54+
"startedWorkerIdentity": "worker-1",
55+
"state": "started",
5856
}
5957
`;
6058

61-
exports[`formatWorkflowHistoryEvent should format workflow pendingDecisionTaskScheduleEventAttributes to match snapshot 1`] = `
59+
exports[`formatWorkflowHistoryEvent should format workflow pendingDecisionTaskStartEventAttributes to match snapshot 1`] = `
6260
{
6361
"attempt": 1,
64-
"eventId": 2,
6562
"eventTime": 2024-09-07T22:16:10.599Z,
66-
"eventType": "PendingDecisionTaskSchedule",
63+
"eventType": "PendingDecisionTaskStart",
6764
"originalScheduledTime": null,
6865
"scheduleId": 7,
6966
"scheduledTime": 1970-01-01T00:03:00.000Z,
7067
"startedTime": null,
68+
"state": "scheduled",
69+
}
70+
`;
71+
72+
exports[`formatWorkflowHistoryEvent should format workflow pendingDecisionTaskStartEventAttributes to match snapshot 2`] = `
73+
{
74+
"attempt": 1,
75+
"eventTime": 2024-09-07T22:16:10.599Z,
76+
"eventType": "PendingDecisionTaskStart",
77+
"originalScheduledTime": null,
78+
"scheduleId": 7,
79+
"scheduledTime": 1970-01-01T00:03:00.000Z,
80+
"startedTime": 2024-09-07T22:16:10.599Z,
81+
"state": "started",
7182
}
7283
`;

src/utils/data-formatters/format-pending-workflow-history-event/format-pending-activity-start-event.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ export default function formatPendingActivityTaskStartEvent({
1818
...eventAttributes
1919
},
2020
eventTime,
21-
eventId,
2221
}: PendingActivityTaskStartEvent) {
2322
return {
2423
...eventAttributes,
25-
eventId,
2624
eventTime: formatTimestampToDatetime(eventTime),
2725
eventType: 'PendingActivityTaskStart',
2826
state: formatEnum(state, 'PENDING_ACTIVITY_STATE', 'pascal'),

src/utils/data-formatters/format-pending-workflow-history-event/format-pending-decision-schedule-event.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { type PendingDecisionTaskStartEvent } from '@/views/workflow-history/workflow-history.types';
2+
3+
import formatEnum from '../format-enum';
4+
import formatTimestampToDatetime from '../format-timestamp-to-datetime';
5+
6+
const formatPendingDecisionTaskStartEvent = ({
7+
pendingDecisionTaskStartEventAttributes: {
8+
state,
9+
scheduleId,
10+
startedTime,
11+
scheduledTime,
12+
originalScheduledTime,
13+
...eventAttributes
14+
},
15+
eventTime,
16+
}: PendingDecisionTaskStartEvent) => {
17+
return {
18+
...eventAttributes,
19+
state: formatEnum(state, 'PENDING_DECISION_STATE', 'pascal'),
20+
eventType: 'PendingDecisionTaskStart',
21+
eventTime: formatTimestampToDatetime(eventTime),
22+
scheduleId: parseInt(scheduleId),
23+
scheduledTime: formatTimestampToDatetime(scheduledTime),
24+
startedTime: formatTimestampToDatetime(startedTime),
25+
originalScheduledTime: formatTimestampToDatetime(originalScheduledTime),
26+
};
27+
};
28+
29+
export default formatPendingDecisionTaskStartEvent;

src/utils/data-formatters/schema/format-history-pending-event-schema.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ import { type z } from 'zod';
33
import { type PendingHistoryEvent } from '@/views/workflow-history/workflow-history.types';
44

55
import formatPendingActivityTaskStartEvent from '../format-pending-workflow-history-event/format-pending-activity-start-event';
6-
import formatPendingDecisionTaskScheduleEvent from '../format-pending-workflow-history-event/format-pending-decision-schedule-event';
6+
import formatPendingDecisionTaskStartEvent from '../format-pending-workflow-history-event/format-pending-decision-start-event';
77

88
import {
99
pendingActivityTaskStartSchema,
10-
pendingDecisionTaskScheduleSchema,
10+
pendingDecisionTaskStartSchema,
1111
} from './pending-history-event-schema';
1212

1313
export const formatPendingActivityTaskStartEventSchema =
1414
pendingActivityTaskStartSchema.transform(formatPendingActivityTaskStartEvent);
1515

16-
export const formatPendingDecisionTaskScheduleEventSchema =
17-
pendingDecisionTaskScheduleSchema.transform(
18-
formatPendingDecisionTaskScheduleEvent
19-
);
16+
export const formatPendingDecisionTaskStartEventSchema =
17+
pendingDecisionTaskStartSchema.transform(formatPendingDecisionTaskStartEvent);
2018

2119
function unExistingEventType(_: never) {
2220
return null;
@@ -25,8 +23,8 @@ export const getFormatPendingEventSchema = (event: PendingHistoryEvent) => {
2523
switch (event.attributes) {
2624
case 'pendingActivityTaskStartEventAttributes':
2725
return formatPendingActivityTaskStartEventSchema;
28-
case 'pendingDecisionTaskScheduleEventAttributes':
29-
return formatPendingDecisionTaskScheduleEventSchema;
26+
case 'pendingDecisionTaskStartEventAttributes':
27+
return formatPendingDecisionTaskStartEventSchema;
3028
default:
3129
return unExistingEventType(event); // used to show a type error if any pending event attributes cases are not covered
3230
}
@@ -36,7 +34,7 @@ export type FormattedPendingActivityTaskStartEvent = z.infer<
3634
typeof formatPendingActivityTaskStartEventSchema
3735
>;
3836
export type FormattedPendingDecisionTaskScheduleEvent = z.infer<
39-
typeof formatPendingDecisionTaskScheduleEventSchema
37+
typeof formatPendingDecisionTaskStartEventSchema
4038
>;
4139

4240
export type FormattedHistoryPendingEvent =

src/utils/data-formatters/schema/pending-history-event-schema.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ export const pendingActivityTaskStartSchema = z.object({
4747
}),
4848
});
4949

50-
export const pendingDecisionTaskScheduleSchema = z.object({
51-
attributes: z.literal('pendingDecisionTaskScheduleEventAttributes'),
50+
export const pendingDecisionTaskStartSchema = z.object({
51+
attributes: z.literal('pendingDecisionTaskStartEventAttributes'),
5252
eventTime: timestampSchema.nullable(),
53-
eventId: z.string(),
54-
pendingDecisionTaskScheduleEventAttributes: z.object({
55-
state: z.literal(PendingDecisionState.PENDING_DECISION_STATE_SCHEDULED),
53+
eventId: z.null(),
54+
computedEventId: z.string(),
55+
pendingDecisionTaskStartEventAttributes: z.object({
56+
state: z.enum([
57+
PendingDecisionState.PENDING_DECISION_STATE_SCHEDULED,
58+
PendingDecisionState.PENDING_DECISION_STATE_STARTED,
59+
]),
5660
scheduledTime: timestampSchema.nullable(),
5761
startedTime: timestampSchema.nullable(),
5862
attempt: z.number(),

src/views/workflow-history/__fixtures__/all-workflow-event-types-attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const allAttrsArr = arrayOfAllAttrs([
6666
const allAttrsArrExtended = arrayOfAllAttrsExtended([
6767
...allAttrsArr,
6868
'pendingActivityTaskStartEventAttributes',
69-
'pendingDecisionTaskScheduleEventAttributes',
69+
'pendingDecisionTaskStartEventAttributes',
7070
]);
7171

7272
export const allWorkflowEventTypesAttrs: Pick<HistoryEvent, 'attributes'>[] =

src/views/workflow-history/__fixtures__/all-workflow-event-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
timeoutDecisionTaskEvent,
2525
} from './workflow-history-decision-events';
2626
import {
27-
pendingDecisionTaskScheduleEvent,
27+
pendingDecisionTaskStartEvent,
2828
pendingActivityTaskStartEvent,
2929
} from './workflow-history-pending-events';
3030
import {
@@ -106,6 +106,6 @@ export const allWorkflowEvents = [
106106

107107
export const allWorkflowEventsExtended = [
108108
...allWorkflowEvents,
109-
pendingDecisionTaskScheduleEvent,
109+
pendingDecisionTaskStartEvent,
110110
pendingActivityTaskStartEvent,
111111
];

src/views/workflow-history/__fixtures__/workflow-history-pending-events.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {
22
PendingActivityTaskStartEvent,
3-
PendingDecisionTaskScheduleEvent,
3+
PendingDecisionTaskStartEvent,
44
} from '../workflow-history.types';
55

66
export const pendingActivityTaskStartEvent = {
@@ -16,7 +16,6 @@ export const pendingActivityTaskStartEvent = {
1616
activityType: {
1717
name: 'activity.cron.Start',
1818
},
19-
2019
heartbeatDetails: {
2120
data: 'MTcyNTc0NzM3MDU3NTQwOTg0MwoiZ2FkZW5jZS1jYW5hcnkteGRjIgoid29ya2Zsb3cuc2FuaXR5Igo=',
2221
},
@@ -38,27 +37,32 @@ export const pendingActivityTaskStartEvent = {
3837
nanos: 0,
3938
},
4039
scheduleId: '7',
41-
startedWorkerIdentity: '',
42-
state: 'PENDING_ACTIVITY_STATE_STARTED',
40+
startedWorkerIdentity: 'worker-1',
41+
state: 'PENDING_ACTIVITY_STATE_SCHEDULED',
4342
},
4443
} as const satisfies PendingActivityTaskStartEvent;
4544

46-
export const pendingActivityTaskStartEventWithScheduledState = {
45+
export const pendingActivityTaskStartEventWithStartedState = {
4746
...pendingActivityTaskStartEvent,
4847
pendingActivityTaskStartEventAttributes: {
4948
...pendingActivityTaskStartEvent.pendingActivityTaskStartEventAttributes,
50-
state: 'PENDING_ACTIVITY_STATE_SCHEDULED',
49+
state: 'PENDING_ACTIVITY_STATE_STARTED',
50+
lastStartedTime: {
51+
seconds: '1725747370',
52+
nanos: 599547391,
53+
},
5154
},
5255
} as const satisfies PendingActivityTaskStartEvent;
5356

54-
export const pendingDecisionTaskScheduleEvent = {
55-
eventId: '2',
56-
attributes: 'pendingDecisionTaskScheduleEventAttributes',
57+
export const pendingDecisionTaskStartEvent = {
58+
eventId: null,
59+
computedEventId: 'pending-7',
60+
attributes: 'pendingDecisionTaskStartEventAttributes',
5761
eventTime: {
5862
seconds: '1725747370',
5963
nanos: 599547391,
6064
},
61-
pendingDecisionTaskScheduleEventAttributes: {
65+
pendingDecisionTaskStartEventAttributes: {
6266
originalScheduledTime: null,
6367
startedTime: null,
6468
attempt: 1,
@@ -69,4 +73,16 @@ export const pendingDecisionTaskScheduleEvent = {
6973
scheduleId: '7',
7074
state: 'PENDING_DECISION_STATE_SCHEDULED',
7175
},
72-
} as const satisfies PendingDecisionTaskScheduleEvent;
76+
} as const satisfies PendingDecisionTaskStartEvent;
77+
78+
export const pendingDecisionTaskStartEventWithStartedState = {
79+
...pendingDecisionTaskStartEvent,
80+
pendingDecisionTaskStartEventAttributes: {
81+
...pendingDecisionTaskStartEvent.pendingDecisionTaskStartEventAttributes,
82+
state: 'PENDING_DECISION_STATE_STARTED',
83+
startedTime: {
84+
seconds: '1725747370',
85+
nanos: 599547391,
86+
},
87+
},
88+
} as const satisfies PendingDecisionTaskStartEvent;

0 commit comments

Comments
 (0)