Skip to content

Commit 4ce4839

Browse files
authored
Create formatters for timers, external workflows & childworkflows (#683)
* create formatter functions for workflow execution events * type cancel request event api * format activities and decision tasks * add formatters for remaining files
1 parent e290f21 commit 4ce4839

File tree

33 files changed

+1472
-0
lines changed

33 files changed

+1472
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 ActivityTaskCancelRequestedEvent } from './format-workflow-history-event.type';
24+
25+
const formatActivityTaskCancelRequestedEvent = ({
26+
activityTaskCancelRequestedEventAttributes: {
27+
decisionTaskCompletedEventId,
28+
...eventAttributes
29+
},
30+
...eventFields
31+
}: ActivityTaskCancelRequestedEvent) => {
32+
return {
33+
...formatWorkflowCommonEventFields(eventFields),
34+
...eventAttributes,
35+
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
36+
};
37+
};
38+
39+
export default formatActivityTaskCancelRequestedEvent;
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 formatPayload from '../format-payload';
23+
24+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
25+
import { type ActivityTaskCanceledEvent } from './format-workflow-history-event.type';
26+
27+
const formatActivityTaskCanceledEvent = ({
28+
activityTaskCanceledEventAttributes: {
29+
details,
30+
latestCancelRequestedEventId,
31+
scheduledEventId,
32+
startedEventId,
33+
...eventAttributes
34+
},
35+
...eventFields
36+
}: ActivityTaskCanceledEvent) => {
37+
return {
38+
...formatWorkflowCommonEventFields(eventFields),
39+
...eventAttributes,
40+
details: formatPayload(details),
41+
latestCancelRequestedEventId: parseInt(latestCancelRequestedEventId),
42+
scheduledEventId: parseInt(scheduledEventId),
43+
startedEventId: parseInt(startedEventId),
44+
};
45+
};
46+
47+
export default formatActivityTaskCanceledEvent;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
24+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
25+
import { type ActivityTaskCompletedEvent } from './format-workflow-history-event.type';
26+
27+
const formatActivityTaskCompletedEvent = ({
28+
activityTaskCompletedEventAttributes: {
29+
result,
30+
scheduledEventId,
31+
startedEventId,
32+
...eventAttributes
33+
},
34+
...eventFields
35+
}: ActivityTaskCompletedEvent) => {
36+
return {
37+
...formatWorkflowCommonEventFields(eventFields),
38+
...eventAttributes,
39+
result: formatPayload(result),
40+
scheduledEventId: parseInt(scheduledEventId),
41+
startedEventId: parseInt(startedEventId),
42+
};
43+
};
44+
45+
export default formatActivityTaskCompletedEvent;
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 formatFailureDetails from '../format-failure-details';
23+
24+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
25+
import { type ActivityTaskFailedEvent } from './format-workflow-history-event.type';
26+
27+
const formatActivityTaskFailedEvent = ({
28+
activityTaskFailedEventAttributes: {
29+
failure,
30+
scheduledEventId,
31+
startedEventId,
32+
...eventAttributes
33+
},
34+
...eventFields
35+
}: ActivityTaskFailedEvent) => {
36+
return {
37+
...formatWorkflowCommonEventFields(eventFields),
38+
...eventAttributes,
39+
details: formatFailureDetails(failure),
40+
reason: failure?.reason || '',
41+
scheduledEventId: parseInt(scheduledEventId),
42+
startedEventId: parseInt(startedEventId),
43+
};
44+
};
45+
46+
export default formatActivityTaskFailedEvent;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 formatPayload from '../format-payload';
25+
import formatPayloadMap from '../format-payload-map';
26+
import formatRetryPolicy from '../format-retry-policy';
27+
28+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
29+
import { type ActivityTaskScheduledEvent } from './format-workflow-history-event.type';
30+
31+
const formatActivityTaskScheduledEvent = ({
32+
activityTaskScheduledEventAttributes: {
33+
decisionTaskCompletedEventId,
34+
domain,
35+
header,
36+
heartbeatTimeout,
37+
input,
38+
retryPolicy,
39+
scheduleToCloseTimeout,
40+
scheduleToStartTimeout,
41+
startToCloseTimeout,
42+
taskList,
43+
...eventAttributes
44+
},
45+
...eventFields
46+
}: ActivityTaskScheduledEvent) => {
47+
return {
48+
...formatWorkflowCommonEventFields(eventFields),
49+
...eventAttributes,
50+
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
51+
domain: domain || null,
52+
header: formatPayloadMap(header, 'fields'),
53+
heartbeatTimeoutSeconds: formatDurationToSeconds(heartbeatTimeout),
54+
input: formatPayload(input),
55+
retryPolicy: formatRetryPolicy(retryPolicy),
56+
scheduleToCloseTimeoutSeconds: formatDurationToSeconds(
57+
scheduleToCloseTimeout
58+
),
59+
scheduleToStartTimeoutSeconds: formatDurationToSeconds(
60+
scheduleToStartTimeout
61+
),
62+
startToCloseTimeoutSeconds: formatDurationToSeconds(startToCloseTimeout),
63+
taskList: {
64+
kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'),
65+
name: taskList?.name || null,
66+
},
67+
};
68+
};
69+
70+
export default formatActivityTaskScheduledEvent;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
24+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
25+
import { type ActivityTaskStartedEvent } from './format-workflow-history-event.type';
26+
27+
const formatActivityTaskStartedEvent = ({
28+
activityTaskStartedEventAttributes: {
29+
lastFailure,
30+
scheduledEventId,
31+
...eventAttributes
32+
},
33+
...eventFields
34+
}: ActivityTaskStartedEvent) => {
35+
return {
36+
...formatWorkflowCommonEventFields(eventFields),
37+
...eventAttributes,
38+
lastFailureDetails: formatFailureDetails(lastFailure),
39+
lastFailureReason: lastFailure?.reason || '',
40+
scheduledEventId: parseInt(scheduledEventId),
41+
};
42+
};
43+
44+
export default formatActivityTaskStartedEvent;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 formatPayload from '../format-payload';
24+
25+
import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
26+
import { type ActivityTaskTimedOutEvent } from './format-workflow-history-event.type';
27+
28+
const formatActivityTaskTimedOutEvent = ({
29+
activityTaskTimedOutEventAttributes: {
30+
details,
31+
lastFailure,
32+
scheduledEventId,
33+
startedEventId,
34+
...eventAttributes
35+
},
36+
...eventFields
37+
}: ActivityTaskTimedOutEvent) => {
38+
return {
39+
...formatWorkflowCommonEventFields(eventFields),
40+
...eventAttributes,
41+
details: formatPayload(details),
42+
lastFailureDetails: formatFailureDetails(lastFailure),
43+
lastFailureReason: lastFailure?.reason || '',
44+
scheduledEventId: parseInt(scheduledEventId),
45+
startedEventId: parseInt(startedEventId),
46+
};
47+
};
48+
49+
export default formatActivityTaskTimedOutEvent;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 CancelTimerFailedEvent } from './format-workflow-history-event.type';
24+
25+
const formatCancelTimerFailedEvent = ({
26+
cancelTimerFailedEventAttributes: {
27+
decisionTaskCompletedEventId,
28+
...eventAttributes
29+
},
30+
...eventFields
31+
}: CancelTimerFailedEvent) => {
32+
return {
33+
...formatWorkflowCommonEventFields(eventFields),
34+
...eventAttributes,
35+
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
36+
};
37+
};
38+
39+
export default formatCancelTimerFailedEvent;

0 commit comments

Comments
 (0)