Skip to content

Commit

Permalink
Create formatters for timers, external workflows & childworkflows (#683)
Browse files Browse the repository at this point in the history
* create formatter functions for workflow execution events

* type cancel request event api

* format activities and decision tasks

* add formatters for remaining files
  • Loading branch information
Assem-Hafez authored Sep 30, 2024
1 parent e290f21 commit 4ce4839
Show file tree
Hide file tree
Showing 33 changed files with 1,472 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskCancelRequestedEvent } from './format-workflow-history-event.type';

const formatActivityTaskCancelRequestedEvent = ({
activityTaskCancelRequestedEventAttributes: {
decisionTaskCompletedEventId,
...eventAttributes
},
...eventFields
}: ActivityTaskCancelRequestedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
};
};

export default formatActivityTaskCancelRequestedEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatPayload from '../format-payload';

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskCanceledEvent } from './format-workflow-history-event.type';

const formatActivityTaskCanceledEvent = ({
activityTaskCanceledEventAttributes: {
details,
latestCancelRequestedEventId,
scheduledEventId,
startedEventId,
...eventAttributes
},
...eventFields
}: ActivityTaskCanceledEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
details: formatPayload(details),
latestCancelRequestedEventId: parseInt(latestCancelRequestedEventId),
scheduledEventId: parseInt(scheduledEventId),
startedEventId: parseInt(startedEventId),
};
};

export default formatActivityTaskCanceledEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatPayload from '../format-payload';

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskCompletedEvent } from './format-workflow-history-event.type';

const formatActivityTaskCompletedEvent = ({
activityTaskCompletedEventAttributes: {
result,
scheduledEventId,
startedEventId,
...eventAttributes
},
...eventFields
}: ActivityTaskCompletedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
result: formatPayload(result),
scheduledEventId: parseInt(scheduledEventId),
startedEventId: parseInt(startedEventId),
};
};

export default formatActivityTaskCompletedEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatFailureDetails from '../format-failure-details';

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskFailedEvent } from './format-workflow-history-event.type';

const formatActivityTaskFailedEvent = ({
activityTaskFailedEventAttributes: {
failure,
scheduledEventId,
startedEventId,
...eventAttributes
},
...eventFields
}: ActivityTaskFailedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
details: formatFailureDetails(failure),
reason: failure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
startedEventId: parseInt(startedEventId),
};
};

export default formatActivityTaskFailedEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatDurationToSeconds from '../format-duration-to-seconds';
import formatEnum from '../format-enum';
import formatPayload from '../format-payload';
import formatPayloadMap from '../format-payload-map';
import formatRetryPolicy from '../format-retry-policy';

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskScheduledEvent } from './format-workflow-history-event.type';

const formatActivityTaskScheduledEvent = ({
activityTaskScheduledEventAttributes: {
decisionTaskCompletedEventId,
domain,
header,
heartbeatTimeout,
input,
retryPolicy,
scheduleToCloseTimeout,
scheduleToStartTimeout,
startToCloseTimeout,
taskList,
...eventAttributes
},
...eventFields
}: ActivityTaskScheduledEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
domain: domain || null,
header: formatPayloadMap(header, 'fields'),
heartbeatTimeoutSeconds: formatDurationToSeconds(heartbeatTimeout),
input: formatPayload(input),
retryPolicy: formatRetryPolicy(retryPolicy),
scheduleToCloseTimeoutSeconds: formatDurationToSeconds(
scheduleToCloseTimeout
),
scheduleToStartTimeoutSeconds: formatDurationToSeconds(
scheduleToStartTimeout
),
startToCloseTimeoutSeconds: formatDurationToSeconds(startToCloseTimeout),
taskList: {
kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'),
name: taskList?.name || null,
},
};
};

export default formatActivityTaskScheduledEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatFailureDetails from '../format-failure-details';

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskStartedEvent } from './format-workflow-history-event.type';

const formatActivityTaskStartedEvent = ({
activityTaskStartedEventAttributes: {
lastFailure,
scheduledEventId,
...eventAttributes
},
...eventFields
}: ActivityTaskStartedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
lastFailureDetails: formatFailureDetails(lastFailure),
lastFailureReason: lastFailure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
};
};

export default formatActivityTaskStartedEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatFailureDetails from '../format-failure-details';
import formatPayload from '../format-payload';

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type ActivityTaskTimedOutEvent } from './format-workflow-history-event.type';

const formatActivityTaskTimedOutEvent = ({
activityTaskTimedOutEventAttributes: {
details,
lastFailure,
scheduledEventId,
startedEventId,
...eventAttributes
},
...eventFields
}: ActivityTaskTimedOutEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
details: formatPayload(details),
lastFailureDetails: formatFailureDetails(lastFailure),
lastFailureReason: lastFailure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
startedEventId: parseInt(startedEventId),
};
};

export default formatActivityTaskTimedOutEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2022-2024 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import formatWorkflowCommonEventFields from './format-workflow-common-event-fields';
import { type CancelTimerFailedEvent } from './format-workflow-history-event.type';

const formatCancelTimerFailedEvent = ({
cancelTimerFailedEventAttributes: {
decisionTaskCompletedEventId,
...eventAttributes
},
...eventFields
}: CancelTimerFailedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
};
};

export default formatCancelTimerFailedEvent;
Loading

0 comments on commit 4ce4839

Please sign in to comment.