Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create formatter functions for workflow execution events #681

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent';

import formatTimestampToDatetime from '../format-timestamp-to-datetime';
import formatWorkflowHistoryEventType from '../format-workflow-history-event-type';

export default function formatWorkflowCommonEventFields<
T extends HistoryEvent['attributes'],
>({
eventId,
eventTime,
attributes,
...rest
}: {
eventId: HistoryEvent['eventId'];
eventTime: HistoryEvent['eventTime'];
attributes: T;
}) {
return {
...rest,
eventId: parseInt(eventId),
timestamp: formatTimestampToDatetime(eventTime),
eventType: formatWorkflowHistoryEventType<T>(attributes),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 WorkflowExecutionCancelRequestedEvent } from './format-workflow-history-event.type';

const formatWorkflowExecutionCancelRequestedEvent = ({
workflowExecutionCancelRequestedEventAttributes: {
externalExecutionInfo,
...eventAttributes
},
...eventFields
}: WorkflowExecutionCancelRequestedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
externalInitiatedEventId: externalExecutionInfo?.initiatedId
? parseInt(externalExecutionInfo.initiatedId)
: null,
externalWorkflowExecution: externalExecutionInfo?.workflowExecution,
};
};

export default formatWorkflowExecutionCancelRequestedEvent;
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 formatPayload from '../format-payload';
import formatWorkflowEventId from '../format-workflow-event-id';

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

const formatWorkflowExecutionCanceledEvent = ({
workflowExecutionCanceledEventAttributes: {
decisionTaskCompletedEventId,
details,
...eventAttributes
},
...eventFields
}: WorkflowExecutionCanceledEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
decisionTaskCompletedEventId: formatWorkflowEventId(
decisionTaskCompletedEventId
),
details: formatPayload(details),
};
};

export default formatWorkflowExecutionCanceledEvent;
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 formatPayload from '../format-payload';
import formatWorkflowEventId from '../format-workflow-event-id';

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

const formatWorkflowExecutionCompletedEvent = ({
workflowExecutionCompletedEventAttributes: {
decisionTaskCompletedEventId,
result,
...eventAttributes
},
...eventFields
}: WorkflowExecutionCompletedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
decisionTaskCompletedEventId: formatWorkflowEventId(
decisionTaskCompletedEventId
),
result: formatPayload(result),
};
};

export default formatWorkflowExecutionCompletedEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 formatFailureDetails from '../format-failure-details';
import formatPayloadMap from '../format-payload-map';
import formatWorkflowEventId from '../format-workflow-event-id';
import formatWorkflowInputPayload from '../format-workflow-input-payload';

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

const formatWorkflowExecutionContinuedAsNewEvent = ({
workflowExecutionContinuedAsNewEventAttributes: {
backoffStartInterval,
decisionTaskCompletedEventId,
executionStartToCloseTimeout,
failure,
header,
initiator,
input,
memo,
searchAttributes,
taskList,
taskStartToCloseTimeout,
...eventAttributes
},
...eventFields
}: WorkflowExecutionContinuedAsNewEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
backoffStartIntervalInSeconds:
formatDurationToSeconds(backoffStartInterval),
decisionTaskCompletedEventId: formatWorkflowEventId(
decisionTaskCompletedEventId
),
executionStartToCloseTimeoutSeconds: formatDurationToSeconds(
executionStartToCloseTimeout
),
failureDetails: formatFailureDetails(failure),
failureReason: failure?.reason || '',
header: formatPayloadMap(header, 'fields'),
initiator: formatEnum(initiator, 'CONTINUE_AS_NEW_INITIATOR'),
input: formatWorkflowInputPayload(input),
memo: formatPayloadMap(memo, 'fields'),
searchAttributes: formatPayloadMap(searchAttributes, 'indexedFields'),
taskList: {
kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'),
name: taskList?.name || null,
},
taskStartToCloseTimeoutSeconds: formatDurationToSeconds(
taskStartToCloseTimeout
),
};
};

export default formatWorkflowExecutionContinuedAsNewEvent;
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 formatFailureDetails from '../format-failure-details';
import formatWorkflowEventId from '../format-workflow-event-id';

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

const formatWorkflowExecutionFailedEvent = ({
workflowExecutionFailedEventAttributes: {
decisionTaskCompletedEventId,
failure,
...eventAttributes
},
...eventFields
}: WorkflowExecutionFailedEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
decisionTaskCompletedEventId: formatWorkflowEventId(
decisionTaskCompletedEventId
),
details: formatFailureDetails(failure),
reason: failure?.reason || '',
};
};

export default formatWorkflowExecutionFailedEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 formatWorkflowInputPayload from '../format-workflow-input-payload';

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

const formatWorkflowExecutionSignaledEvent = ({
workflowExecutionSignaledEventAttributes: { input, ...eventAttributes },
...eventFields
}: WorkflowExecutionSignaledEvent) => {
return {
...formatWorkflowCommonEventFields(eventFields),
...eventAttributes,
input: formatWorkflowInputPayload(input),
};
};

export default formatWorkflowExecutionSignaledEvent;
Loading
Loading