Skip to content

Commit 5575cc6

Browse files
authored
Create formatter functions for workflow execution events (#681)
* create formatter functions for workflow execution events * type cancel request event api
1 parent f9c5df6 commit 5575cc6

11 files changed

+751
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent';
2+
3+
import formatTimestampToDatetime from '../format-timestamp-to-datetime';
4+
import formatWorkflowHistoryEventType from '../format-workflow-history-event-type';
5+
6+
export default function formatWorkflowCommonEventFields<
7+
T extends HistoryEvent['attributes'],
8+
>({
9+
eventId,
10+
eventTime,
11+
attributes,
12+
...rest
13+
}: {
14+
eventId: HistoryEvent['eventId'];
15+
eventTime: HistoryEvent['eventTime'];
16+
attributes: T;
17+
}) {
18+
return {
19+
...rest,
20+
eventId: parseInt(eventId),
21+
timestamp: formatTimestampToDatetime(eventTime),
22+
eventType: formatWorkflowHistoryEventType<T>(attributes),
23+
};
24+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2022-2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
23+
import { type WorkflowExecutionCancelRequestedEvent } from './format-workflow-history-event.type';
24+
25+
const formatWorkflowExecutionCancelRequestedEvent = ({
26+
workflowExecutionCancelRequestedEventAttributes: {
27+
externalExecutionInfo,
28+
...eventAttributes
29+
},
30+
...eventFields
31+
}: WorkflowExecutionCancelRequestedEvent) => {
32+
return {
33+
...formatWorkflowCommonEventFields(eventFields),
34+
...eventAttributes,
35+
externalInitiatedEventId: externalExecutionInfo?.initiatedId
36+
? parseInt(externalExecutionInfo.initiatedId)
37+
: null,
38+
externalWorkflowExecution: externalExecutionInfo?.workflowExecution,
39+
};
40+
};
41+
42+
export default formatWorkflowExecutionCancelRequestedEvent;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2022-2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import formatPayload from '../format-payload';
23+
import formatWorkflowEventId from '../format-workflow-event-id';
24+
25+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
26+
import { type WorkflowExecutionCanceledEvent } from './format-workflow-history-event.type';
27+
28+
const formatWorkflowExecutionCanceledEvent = ({
29+
workflowExecutionCanceledEventAttributes: {
30+
decisionTaskCompletedEventId,
31+
details,
32+
...eventAttributes
33+
},
34+
...eventFields
35+
}: WorkflowExecutionCanceledEvent) => {
36+
return {
37+
...formatWorkflowCommonEventFields(eventFields),
38+
...eventAttributes,
39+
decisionTaskCompletedEventId: formatWorkflowEventId(
40+
decisionTaskCompletedEventId
41+
),
42+
details: formatPayload(details),
43+
};
44+
};
45+
46+
export default formatWorkflowExecutionCanceledEvent;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2022-2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import formatPayload from '../format-payload';
23+
import formatWorkflowEventId from '../format-workflow-event-id';
24+
25+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
26+
import { type WorkflowExecutionCompletedEvent } from './format-workflow-history-event.type';
27+
28+
const formatWorkflowExecutionCompletedEvent = ({
29+
workflowExecutionCompletedEventAttributes: {
30+
decisionTaskCompletedEventId,
31+
result,
32+
...eventAttributes
33+
},
34+
...eventFields
35+
}: WorkflowExecutionCompletedEvent) => {
36+
return {
37+
...formatWorkflowCommonEventFields(eventFields),
38+
...eventAttributes,
39+
decisionTaskCompletedEventId: formatWorkflowEventId(
40+
decisionTaskCompletedEventId
41+
),
42+
result: formatPayload(result),
43+
};
44+
};
45+
46+
export default formatWorkflowExecutionCompletedEvent;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2022-2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import formatDurationToSeconds from '../format-duration-to-seconds';
23+
import formatEnum from '../format-enum';
24+
import formatFailureDetails from '../format-failure-details';
25+
import formatPayloadMap from '../format-payload-map';
26+
import formatWorkflowEventId from '../format-workflow-event-id';
27+
import formatWorkflowInputPayload from '../format-workflow-input-payload';
28+
29+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
30+
import { type WorkflowExecutionContinuedAsNewEvent } from './format-workflow-history-event.type';
31+
32+
const formatWorkflowExecutionContinuedAsNewEvent = ({
33+
workflowExecutionContinuedAsNewEventAttributes: {
34+
backoffStartInterval,
35+
decisionTaskCompletedEventId,
36+
executionStartToCloseTimeout,
37+
failure,
38+
header,
39+
initiator,
40+
input,
41+
memo,
42+
searchAttributes,
43+
taskList,
44+
taskStartToCloseTimeout,
45+
...eventAttributes
46+
},
47+
...eventFields
48+
}: WorkflowExecutionContinuedAsNewEvent) => {
49+
return {
50+
...formatWorkflowCommonEventFields(eventFields),
51+
...eventAttributes,
52+
backoffStartIntervalInSeconds:
53+
formatDurationToSeconds(backoffStartInterval),
54+
decisionTaskCompletedEventId: formatWorkflowEventId(
55+
decisionTaskCompletedEventId
56+
),
57+
executionStartToCloseTimeoutSeconds: formatDurationToSeconds(
58+
executionStartToCloseTimeout
59+
),
60+
failureDetails: formatFailureDetails(failure),
61+
failureReason: failure?.reason || '',
62+
header: formatPayloadMap(header, 'fields'),
63+
initiator: formatEnum(initiator, 'CONTINUE_AS_NEW_INITIATOR'),
64+
input: formatWorkflowInputPayload(input),
65+
memo: formatPayloadMap(memo, 'fields'),
66+
searchAttributes: formatPayloadMap(searchAttributes, 'indexedFields'),
67+
taskList: {
68+
kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'),
69+
name: taskList?.name || null,
70+
},
71+
taskStartToCloseTimeoutSeconds: formatDurationToSeconds(
72+
taskStartToCloseTimeout
73+
),
74+
};
75+
};
76+
77+
export default formatWorkflowExecutionContinuedAsNewEvent;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2022-2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import formatFailureDetails from '../format-failure-details';
23+
import formatWorkflowEventId from '../format-workflow-event-id';
24+
25+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
26+
import { type WorkflowExecutionFailedEvent } from './format-workflow-history-event.type';
27+
28+
const formatWorkflowExecutionFailedEvent = ({
29+
workflowExecutionFailedEventAttributes: {
30+
decisionTaskCompletedEventId,
31+
failure,
32+
...eventAttributes
33+
},
34+
...eventFields
35+
}: WorkflowExecutionFailedEvent) => {
36+
return {
37+
...formatWorkflowCommonEventFields(eventFields),
38+
...eventAttributes,
39+
decisionTaskCompletedEventId: formatWorkflowEventId(
40+
decisionTaskCompletedEventId
41+
),
42+
details: formatFailureDetails(failure),
43+
reason: failure?.reason || '',
44+
};
45+
};
46+
47+
export default formatWorkflowExecutionFailedEvent;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2022-2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import formatWorkflowInputPayload from '../format-workflow-input-payload';
23+
24+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
25+
import { type WorkflowExecutionSignaledEvent } from './format-workflow-history-event.type';
26+
27+
const formatWorkflowExecutionSignaledEvent = ({
28+
workflowExecutionSignaledEventAttributes: { input, ...eventAttributes },
29+
...eventFields
30+
}: WorkflowExecutionSignaledEvent) => {
31+
return {
32+
...formatWorkflowCommonEventFields(eventFields),
33+
...eventAttributes,
34+
input: formatWorkflowInputPayload(input),
35+
};
36+
};
37+
38+
export default formatWorkflowExecutionSignaledEvent;

0 commit comments

Comments
 (0)