From 645d42a67eb6ef1ea8ea5551e0ce7e6e6b571281 Mon Sep 17 00:00:00 2001 From: Daryl Lim <5508348+daryllimyt@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:59:12 +0000 Subject: [PATCH] refactor(app): Rename `EventHistoryType` -> `WorkflowEventType` (#766) --- docs/openapi.yml | 44 +++++++++++----------- frontend/src/client/schemas.gen.ts | 50 ++++++++++++------------- frontend/src/client/types.gen.ts | 44 +++++++++++----------- tests/unit/test_workflows.py | 10 ++--- tracecat/workflow/executions/models.py | 4 +- tracecat/workflow/executions/service.py | 34 ++++++++--------- 6 files changed, 93 insertions(+), 93 deletions(-) diff --git a/docs/openapi.yml b/docs/openapi.yml index e756ec7e5..e4682e92b 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -4314,27 +4314,6 @@ components: - udf_key - action_input title: EventGroup - EventHistoryType: - type: string - enum: - - WORKFLOW_EXECUTION_STARTED - - WORKFLOW_EXECUTION_COMPLETED - - WORKFLOW_EXECUTION_FAILED - - WORKFLOW_EXECUTION_TERMINATED - - WORKFLOW_EXECUTION_CANCELED - - WORKFLOW_EXECUTION_CONTINUED_AS_NEW - - WORKFLOW_EXECUTION_TIMED_OUT - - ACTIVITY_TASK_SCHEDULED - - ACTIVITY_TASK_STARTED - - ACTIVITY_TASK_COMPLETED - - ACTIVITY_TASK_FAILED - - ACTIVITY_TASK_TIMED_OUT - - CHILD_WORKFLOW_EXECUTION_STARTED - - CHILD_WORKFLOW_EXECUTION_COMPLETED - - CHILD_WORKFLOW_EXECUTION_FAILED - - START_CHILD_WORKFLOW_EXECUTION_INITIATED - title: EventHistoryType - description: The event types we care about. ExpectedField: properties: type: @@ -6202,6 +6181,27 @@ components: ------------- - 1 Workflow to many WorkflowDefinitions' + WorkflowEventType: + type: string + enum: + - WORKFLOW_EXECUTION_STARTED + - WORKFLOW_EXECUTION_COMPLETED + - WORKFLOW_EXECUTION_FAILED + - WORKFLOW_EXECUTION_TERMINATED + - WORKFLOW_EXECUTION_CANCELED + - WORKFLOW_EXECUTION_CONTINUED_AS_NEW + - WORKFLOW_EXECUTION_TIMED_OUT + - ACTIVITY_TASK_SCHEDULED + - ACTIVITY_TASK_STARTED + - ACTIVITY_TASK_COMPLETED + - ACTIVITY_TASK_FAILED + - ACTIVITY_TASK_TIMED_OUT + - CHILD_WORKFLOW_EXECUTION_STARTED + - CHILD_WORKFLOW_EXECUTION_COMPLETED + - CHILD_WORKFLOW_EXECUTION_FAILED + - START_CHILD_WORKFLOW_EXECUTION_INITIATED + title: WorkflowEventType + description: The event types we care about. WorkflowExecutionCreate: properties: workflow_id: @@ -6246,7 +6246,7 @@ components: format: date-time title: Event Time event_type: - $ref: '#/components/schemas/EventHistoryType' + $ref: '#/components/schemas/WorkflowEventType' task_id: type: integer title: Task Id diff --git a/frontend/src/client/schemas.gen.ts b/frontend/src/client/schemas.gen.ts index bbe3adc3f..d9eb7c813 100644 --- a/frontend/src/client/schemas.gen.ts +++ b/frontend/src/client/schemas.gen.ts @@ -1072,30 +1072,6 @@ export const $EventGroup = { title: "EventGroup", } as const -export const $EventHistoryType = { - type: "string", - enum: [ - "WORKFLOW_EXECUTION_STARTED", - "WORKFLOW_EXECUTION_COMPLETED", - "WORKFLOW_EXECUTION_FAILED", - "WORKFLOW_EXECUTION_TERMINATED", - "WORKFLOW_EXECUTION_CANCELED", - "WORKFLOW_EXECUTION_CONTINUED_AS_NEW", - "WORKFLOW_EXECUTION_TIMED_OUT", - "ACTIVITY_TASK_SCHEDULED", - "ACTIVITY_TASK_STARTED", - "ACTIVITY_TASK_COMPLETED", - "ACTIVITY_TASK_FAILED", - "ACTIVITY_TASK_TIMED_OUT", - "CHILD_WORKFLOW_EXECUTION_STARTED", - "CHILD_WORKFLOW_EXECUTION_COMPLETED", - "CHILD_WORKFLOW_EXECUTION_FAILED", - "START_CHILD_WORKFLOW_EXECUTION_INITIATED", - ], - title: "EventHistoryType", - description: "The event types we care about.", -} as const - export const $ExpectedField = { properties: { type: { @@ -3935,6 +3911,30 @@ Relationships - 1 Workflow to many WorkflowDefinitions`, } as const +export const $WorkflowEventType = { + type: "string", + enum: [ + "WORKFLOW_EXECUTION_STARTED", + "WORKFLOW_EXECUTION_COMPLETED", + "WORKFLOW_EXECUTION_FAILED", + "WORKFLOW_EXECUTION_TERMINATED", + "WORKFLOW_EXECUTION_CANCELED", + "WORKFLOW_EXECUTION_CONTINUED_AS_NEW", + "WORKFLOW_EXECUTION_TIMED_OUT", + "ACTIVITY_TASK_SCHEDULED", + "ACTIVITY_TASK_STARTED", + "ACTIVITY_TASK_COMPLETED", + "ACTIVITY_TASK_FAILED", + "ACTIVITY_TASK_TIMED_OUT", + "CHILD_WORKFLOW_EXECUTION_STARTED", + "CHILD_WORKFLOW_EXECUTION_COMPLETED", + "CHILD_WORKFLOW_EXECUTION_FAILED", + "START_CHILD_WORKFLOW_EXECUTION_INITIATED", + ], + title: "WorkflowEventType", + description: "The event types we care about.", +} as const + export const $WorkflowExecutionCreate = { properties: { workflow_id: { @@ -3991,7 +3991,7 @@ export const $WorkflowExecutionEvent = { title: "Event Time", }, event_type: { - $ref: "#/components/schemas/EventHistoryType", + $ref: "#/components/schemas/WorkflowEventType", }, task_id: { type: "integer", diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index 973af2f07..8fa5aec7f 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -349,27 +349,6 @@ export type EventGroup = { related_wf_exec_id?: string | null } -/** - * The event types we care about. - */ -export type EventHistoryType = - | "WORKFLOW_EXECUTION_STARTED" - | "WORKFLOW_EXECUTION_COMPLETED" - | "WORKFLOW_EXECUTION_FAILED" - | "WORKFLOW_EXECUTION_TERMINATED" - | "WORKFLOW_EXECUTION_CANCELED" - | "WORKFLOW_EXECUTION_CONTINUED_AS_NEW" - | "WORKFLOW_EXECUTION_TIMED_OUT" - | "ACTIVITY_TASK_SCHEDULED" - | "ACTIVITY_TASK_STARTED" - | "ACTIVITY_TASK_COMPLETED" - | "ACTIVITY_TASK_FAILED" - | "ACTIVITY_TASK_TIMED_OUT" - | "CHILD_WORKFLOW_EXECUTION_STARTED" - | "CHILD_WORKFLOW_EXECUTION_COMPLETED" - | "CHILD_WORKFLOW_EXECUTION_FAILED" - | "START_CHILD_WORKFLOW_EXECUTION_INITIATED" - export type ExpectedField = { type: string description?: string | null @@ -1239,6 +1218,27 @@ export type WorkflowDefinition = { } } +/** + * The event types we care about. + */ +export type WorkflowEventType = + | "WORKFLOW_EXECUTION_STARTED" + | "WORKFLOW_EXECUTION_COMPLETED" + | "WORKFLOW_EXECUTION_FAILED" + | "WORKFLOW_EXECUTION_TERMINATED" + | "WORKFLOW_EXECUTION_CANCELED" + | "WORKFLOW_EXECUTION_CONTINUED_AS_NEW" + | "WORKFLOW_EXECUTION_TIMED_OUT" + | "ACTIVITY_TASK_SCHEDULED" + | "ACTIVITY_TASK_STARTED" + | "ACTIVITY_TASK_COMPLETED" + | "ACTIVITY_TASK_FAILED" + | "ACTIVITY_TASK_TIMED_OUT" + | "CHILD_WORKFLOW_EXECUTION_STARTED" + | "CHILD_WORKFLOW_EXECUTION_COMPLETED" + | "CHILD_WORKFLOW_EXECUTION_FAILED" + | "START_CHILD_WORKFLOW_EXECUTION_INITIATED" + export type WorkflowExecutionCreate = { workflow_id: string inputs?: unknown | null @@ -1253,7 +1253,7 @@ export type WorkflowExecutionCreateResponse = { export type WorkflowExecutionEvent = { event_id: number event_time: string - event_type: EventHistoryType + event_type: WorkflowEventType task_id: number /** * The action group of the event. We use this to keep track of what events are related to each other. diff --git a/tests/unit/test_workflows.py b/tests/unit/test_workflows.py index 93f06429c..9637e9f16 100644 --- a/tests/unit/test_workflows.py +++ b/tests/unit/test_workflows.py @@ -49,7 +49,7 @@ from tracecat.types.auth import Role from tracecat.workflow.executions.models import ( EventGroup, - EventHistoryType, + WorkflowEventType, WorkflowExecutionEvent, ) from tracecat.workflow.executions.service import WorkflowExecutionsService @@ -2440,7 +2440,7 @@ def assert_erroneous_task_failed_correctly( event for event in events if ( - event.event_type == EventHistoryType.ACTIVITY_TASK_FAILED + event.event_type == WorkflowEventType.ACTIVITY_TASK_FAILED and event.event_group and event.event_group.action_ref == "failing_action" ) @@ -2491,7 +2491,7 @@ def assert_error_handler_initiated_correctly( for event in events if ( event.event_type - == EventHistoryType.START_CHILD_WORKFLOW_EXECUTION_INITIATED + == WorkflowEventType.START_CHILD_WORKFLOW_EXECUTION_INITIATED and event.event_group and event.event_group.action_ref is None and event.event_group.action_title == "Testing Error Handler" @@ -2544,7 +2544,7 @@ def assert_error_handler_started( event for event in events if ( - event.event_type == EventHistoryType.CHILD_WORKFLOW_EXECUTION_STARTED + event.event_type == WorkflowEventType.CHILD_WORKFLOW_EXECUTION_STARTED and event.event_group and event.event_group.action_ref is None and event.event_group.action_title == "Testing Error Handler" @@ -2564,7 +2564,7 @@ def assert_error_handler_completed( event for event in events if ( - event.event_type == EventHistoryType.CHILD_WORKFLOW_EXECUTION_COMPLETED + event.event_type == WorkflowEventType.CHILD_WORKFLOW_EXECUTION_COMPLETED and event.event_group and event.event_group.action_ref is None and event.event_group.action_title == "Testing Error Handler" diff --git a/tracecat/workflow/executions/models.py b/tracecat/workflow/executions/models.py index 52a31039c..51da9823d 100644 --- a/tracecat/workflow/executions/models.py +++ b/tracecat/workflow/executions/models.py @@ -38,7 +38,7 @@ """Mapped literal types for workflow execution statuses.""" -class EventHistoryType(StrEnum): +class WorkflowEventType(StrEnum): """The event types we care about.""" WORKFLOW_EXECUTION_STARTED = "WORKFLOW_EXECUTION_STARTED" @@ -268,7 +268,7 @@ class WorkflowExecutionEvent(BaseModel, Generic[EventInput]): model_config = ConfigDict(arbitrary_types_allowed=True) event_id: int event_time: datetime - event_type: EventHistoryType + event_type: WorkflowEventType task_id: int event_group: EventGroup[EventInput] | None = Field( default=None, diff --git a/tracecat/workflow/executions/service.py b/tracecat/workflow/executions/service.py index d16cc19b5..3e3d702ca 100644 --- a/tracecat/workflow/executions/service.py +++ b/tracecat/workflow/executions/service.py @@ -37,8 +37,8 @@ from tracecat.workflow.executions.models import ( EventFailure, EventGroup, - EventHistoryType, WorkflowDispatchResponse, + WorkflowEventType, WorkflowExecutionCreateResponse, WorkflowExecutionEvent, ) @@ -121,7 +121,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.START_CHILD_WORKFLOW_EXECUTION_INITIATED, + event_type=WorkflowEventType.START_CHILD_WORKFLOW_EXECUTION_INITIATED, event_group=group, task_id=event.task_id, role=group.action_input.role, @@ -135,7 +135,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.CHILD_WORKFLOW_EXECUTION_STARTED, + event_type=WorkflowEventType.CHILD_WORKFLOW_EXECUTION_STARTED, event_group=group, task_id=event.task_id, ) @@ -150,7 +150,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.CHILD_WORKFLOW_EXECUTION_COMPLETED, + event_type=WorkflowEventType.CHILD_WORKFLOW_EXECUTION_COMPLETED, event_group=group, task_id=event.task_id, result=result, @@ -164,7 +164,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.CHILD_WORKFLOW_EXECUTION_FAILED, + event_type=WorkflowEventType.CHILD_WORKFLOW_EXECUTION_FAILED, event_group=group, task_id=event.task_id, failure=EventFailure.from_history_event(event), @@ -182,7 +182,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_STARTED, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_STARTED, parent_wf_exec_id=parent_exec_id, task_id=event.task_id, role=dsl_run_args.role, @@ -197,7 +197,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_COMPLETED, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_COMPLETED, task_id=event.task_id, result=result, ) @@ -207,7 +207,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_FAILED, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_FAILED, task_id=event.task_id, failure=EventFailure.from_history_event(event), ) @@ -217,7 +217,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_TERMINATED, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_TERMINATED, task_id=event.task_id, ) ) @@ -226,7 +226,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_CANCELED, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_CANCELED, task_id=event.task_id, ) ) @@ -235,7 +235,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_CONTINUED_AS_NEW, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_CONTINUED_AS_NEW, task_id=event.task_id, ) ) @@ -244,7 +244,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.WORKFLOW_EXECUTION_TIMED_OUT, + event_type=WorkflowEventType.WORKFLOW_EXECUTION_TIMED_OUT, task_id=event.task_id, ) ) @@ -257,7 +257,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.ACTIVITY_TASK_SCHEDULED, + event_type=WorkflowEventType.ACTIVITY_TASK_SCHEDULED, task_id=event.task_id, event_group=group, ) @@ -275,7 +275,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.ACTIVITY_TASK_STARTED, + event_type=WorkflowEventType.ACTIVITY_TASK_STARTED, task_id=event.task_id, event_group=group, ) @@ -293,7 +293,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.ACTIVITY_TASK_COMPLETED, + event_type=WorkflowEventType.ACTIVITY_TASK_COMPLETED, task_id=event.task_id, event_group=group, result=result, @@ -310,7 +310,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.ACTIVITY_TASK_FAILED, + event_type=WorkflowEventType.ACTIVITY_TASK_FAILED, task_id=event.task_id, event_group=group, failure=EventFailure.from_history_event(event), @@ -324,7 +324,7 @@ async def list_workflow_execution_events( WorkflowExecutionEvent( event_id=event.event_id, event_time=event.event_time.ToDatetime(datetime.UTC), - event_type=EventHistoryType.ACTIVITY_TASK_TIMED_OUT, + event_type=WorkflowEventType.ACTIVITY_TASK_TIMED_OUT, task_id=event.task_id, event_group=group, )