From cb166cbdd47bad9e763bfcd0734405984ec3adcc Mon Sep 17 00:00:00 2001 From: Laurie O Date: Wed, 17 Dec 2025 15:38:57 +1000 Subject: [PATCH] Use AWS's terminology for workflow-type Also rename workflow 'ID' to 'reference' --- README.md | 1 - src/swf_typed/__init__.py | 22 +++++----- src/swf_typed/_decisions.py | 10 +++-- src/swf_typed/_executions.py | 19 ++++++--- src/swf_typed/_history.py | 60 +++++++++++++++++--------- src/swf_typed/_state.py | 4 +- src/swf_typed/_workflows.py | 82 ++++++++++++++++++------------------ 7 files changed, 112 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index e594214..6dcedcb 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ for task in state.tasks: This library has a slight change in terminology from AWS [SDKs](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/swf.html)/[APIs](https://docs.aws.amazon.com/amazonswf/latest/apireference/Welcome.html)/[docs](https://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-welcome.html): -* Workflow type -> workflow * Workflow execution -> execution * Workflow execution `workflowId` -> execution ID * Activity type -> activity diff --git a/src/swf_typed/__init__.py b/src/swf_typed/__init__.py index 8a559eb..e043dd8 100644 --- a/src/swf_typed/__init__.py +++ b/src/swf_typed/__init__.py @@ -13,18 +13,18 @@ from ._domains import undeprecate_domain from ._domains import untag_domain -from ._workflows import WorkflowIdFilter -from ._workflows import WorkflowId -from ._workflows import WorkflowInfo +from ._workflows import WorkflowTypeFilter +from ._workflows import WorkflowTypeReference +from ._workflows import WorkflowTypeInfo from ._workflows import DefaultExecutionConfiguration -from ._workflows import WorkflowDetails - -from ._workflows import delete_workflow -from ._workflows import deprecate_workflow -from ._workflows import describe_workflow -from ._workflows import list_workflows -from ._workflows import register_workflow -from ._workflows import undeprecate_workflow +from ._workflows import WorkflowTypeDetails + +from ._workflows import delete_workflow_type +from ._workflows import deprecate_workflow_type +from ._workflows import describe_workflow_type +from ._workflows import list_workflow_types +from ._workflows import register_workflow_type +from ._workflows import undeprecate_workflow_type from ._activities import ActivityIdFilter from ._activities import ActivityId diff --git a/src/swf_typed/_decisions.py b/src/swf_typed/_decisions.py index e920e88..31e9e33 100644 --- a/src/swf_typed/_decisions.py +++ b/src/swf_typed/_decisions.py @@ -322,7 +322,7 @@ class StartChildWorkflowExecutionDecision(Decision): type: t.ClassVar[str] = "StartChildWorkflowExecution" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow.""" execution: "_executions.CurrentExecutionId" @@ -343,7 +343,7 @@ class StartChildWorkflowExecutionDecision(Decision): def to_api(self): data = super().to_api() data["startChildWorkflowExecutionDecisionAttributes"] = decision_attributes = { - "workflowType": self.workflow.to_api(), + "workflowType": self.workflow_type.to_api(), "workflowId": self.execution.id, } @@ -398,7 +398,7 @@ class DecisionTask(_common.Deserialisable): execution: "_executions.ExecutionId" """Execution which decisions are being made for.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Execution workflow.""" _execution_history_iter: t.Iterable["_history.Event"] @@ -439,7 +439,9 @@ def from_api( return cls( token=data["taskToken"], execution=_executions.ExecutionId.from_api(data["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(data["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + data["workflowType"], + ), _execution_history_iter=execution_history_iter, decision_task_started_execution_history_event_id=data["startedEventId"], previous_decision_task_started_execution_history_event_id=data.get( diff --git a/src/swf_typed/_executions.py b/src/swf_typed/_executions.py index 3fac67b..f92ca01 100644 --- a/src/swf_typed/_executions.py +++ b/src/swf_typed/_executions.py @@ -84,7 +84,7 @@ class ExecutionInfo(_common.Deserialisable): execution: ExecutionId """Execution ID.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Execution workflow.""" started: datetime.datetime @@ -114,7 +114,9 @@ def from_api(cls, data) -> "ExecutionInfo": status_data = data["closeStatus"] return cls( execution=ExecutionId.from_api(data["execution"]), - workflow=_workflows.WorkflowId.from_api(data["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + data["workflowType"], + ), started=data["startTimestamp"], status=ExecutionStatus(status_data), cancel_requested=data["cancelRequested"], @@ -360,11 +362,14 @@ def get_api_args(self): class WorkflowTypeExecutionFilter(ExecutionFilter): """Workflow execution filter on execution workflow-type.""" - workflow: t.Union["_workflows.WorkflowId", "_workflows.WorkflowIdFilter"] + workflow_type: t.Union[ + "_workflows.WorkflowTypeReference", + "_workflows.WorkflowTypeFilter", + ] """Execution workflow.""" def get_api_args(self): - return {"typeFilter": self.workflow.to_api()} + return {"typeFilter": self.workflow_type.to_api()} @dataclasses.dataclass @@ -646,7 +651,7 @@ def signal_execution( def start_execution( - workflow: "_workflows.WorkflowId", + workflow_type: "_workflows.WorkflowTypeReference", execution: CurrentExecutionId, domain: str, input: str = None, @@ -657,7 +662,7 @@ def start_execution( """Start a workflow execution. Args: - workflow: workflow type for execution + workflow_type: workflow type for execution execution: execution workflow-ID domain: domain for execution input: execution input @@ -680,7 +685,7 @@ def start_execution( response = client.start_workflow_execution( domain=domain, workflowId=execution.id, - workflowType=workflow.to_api(), + workflowType=workflow_type.to_api(), **kw, ) return ExecutionId(id=execution.id, run_id=response["runId"]) diff --git a/src/swf_typed/_history.py b/src/swf_typed/_history.py index 8f15da8..6091054 100644 --- a/src/swf_typed/_history.py +++ b/src/swf_typed/_history.py @@ -437,7 +437,7 @@ class ChildWorkflowExecutionCancelledEvent(Event): execution: "_executions.ExecutionId" """Cancelled execution.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" initiated_event_id: int @@ -459,7 +459,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.ExecutionId.from_api(attrs["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), initiated_event_id=attrs["initiatedEventId"], execution_started_event_id=attrs["startedEventId"], details=attrs.get("details"), @@ -475,7 +477,7 @@ class ChildWorkflowExecutionCompletedEvent(Event): execution: "_executions.ExecutionId" """Completed execution.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" initiated_event_id: int @@ -497,7 +499,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.ExecutionId.from_api(attrs["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), initiated_event_id=attrs["initiatedEventId"], execution_started_event_id=attrs["startedEventId"], execution_result=attrs.get("result"), @@ -513,7 +517,7 @@ class ChildWorkflowExecutionFailedEvent(Event): execution: "_executions.ExecutionId" """Failed execution.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" initiated_event_id: int @@ -538,7 +542,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.ExecutionId.from_api(attrs["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), initiated_event_id=attrs["initiatedEventId"], execution_started_event_id=attrs["startedEventId"], reason=attrs.get("reason"), @@ -555,7 +561,7 @@ class ChildWorkflowExecutionStartedEvent(Event): execution: "_executions.ExecutionId" """Started execution.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" initiated_event_id: int @@ -571,7 +577,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.ExecutionId.from_api(attrs["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), initiated_event_id=attrs["initiatedEventId"], ) @@ -585,7 +593,7 @@ class ChildWorkflowExecutionTerminatedEvent(Event): execution: "_executions.ExecutionId" """Terminated execution.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" initiated_event_id: int @@ -604,7 +612,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.ExecutionId.from_api(attrs["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), initiated_event_id=attrs["initiatedEventId"], execution_started_event_id=attrs["startedEventId"], ) @@ -619,7 +629,7 @@ class ChildWorkflowExecutionTimedOutEvent(Event): execution: "_executions.ExecutionId" """Timed-out execution.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" initiated_event_id: int @@ -639,7 +649,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.ExecutionId.from_api(attrs["workflowExecution"]), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), initiated_event_id=attrs["initiatedEventId"], execution_started_event_id=attrs["startedEventId"], ) @@ -1384,7 +1396,7 @@ class StartChildWorkflowExecutionFailedEvent(Event): execution: "_executions.CurrentExecutionId" """Execution to be started.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" cause: StartChildExecutionFailureCause @@ -1409,7 +1421,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.CurrentExecutionId.from_api(attrs), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), cause=StartChildExecutionFailureCause(attrs["cause"]), initiated_event_id=attrs["initiatedEventId"], decision_event_id=attrs["decisionTaskCompletedEventId"], @@ -1428,7 +1442,7 @@ class StartChildWorkflowExecutionInitiatedEvent(Event): execution: "_executions.CurrentExecutionId" """Execution to be started.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow type.""" execution_configuration: "_executions.PartialExecutionConfiguration" @@ -1459,7 +1473,9 @@ def from_api(cls, data): id=data["eventId"], occured=data["eventTimestamp"], execution=_executions.CurrentExecutionId.from_api(attrs), - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), execution_configuration=config, decision_event_id=attrs["decisionTaskCompletedEventId"], execution_input=attrs.get("input"), @@ -1673,7 +1689,7 @@ class WorkflowExecutionContinuedAsNewEvent(Event): guaranteed). """ - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """New execution workflow type.""" decision_event_id: int @@ -1697,7 +1713,9 @@ def from_api(cls, data): occured=data["eventTimestamp"], execution_run_id=attrs["newExecutionRunId"], execution_configuration=config, - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), decision_event_id=attrs["decisionTaskCompletedEventId"], execution_input=attrs.get("input"), execution_tags=attrs.get("tagList"), @@ -1771,7 +1789,7 @@ class WorkflowExecutionStartedEvent(Event): type: t.ClassVar[str] = "WorkflowExecutionStarted" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Execution workflow type.""" execution_configuration: "_executions.PartialExecutionConfiguration" @@ -1805,7 +1823,9 @@ def from_api(cls, data): return cls( id=data["eventId"], occured=data["eventTimestamp"], - workflow=_workflows.WorkflowId.from_api(attrs["workflowType"]), + workflow_type=_workflows.WorkflowTypeReference.from_api( + attrs["workflowType"], + ), execution_configuration=config, execution_input=attrs.get("input"), execution_tags=attrs.get("tagList"), diff --git a/src/swf_typed/_state.py b/src/swf_typed/_state.py index 252a09a..da0d3e0 100644 --- a/src/swf_typed/_state.py +++ b/src/swf_typed/_state.py @@ -167,7 +167,7 @@ class ChildExecutionState: execution: "_executions.ExecutionId" """Child execution ID.""" - workflow: "_workflows.WorkflowId" + workflow_type: "_workflows.WorkflowTypeReference" """Child execution workflow.""" status: "_executions.ExecutionStatus" @@ -525,7 +525,7 @@ def _process_event(self, event: "_history.Event") -> None: execution = ChildExecutionState( execution=event.execution, - workflow=initiation_event.workflow, + workflow_type=initiation_event.workflow_type, status=_executions.ExecutionStatus.started, configuration=initiation_event.execution_configuration, started=event.occured, diff --git a/src/swf_typed/_workflows.py b/src/swf_typed/_workflows.py index edef6c1..f3a53ec 100644 --- a/src/swf_typed/_workflows.py +++ b/src/swf_typed/_workflows.py @@ -13,7 +13,7 @@ @dataclasses.dataclass -class WorkflowId(_common.Deserialisable, _common.Serialisable): +class WorkflowTypeReference(_common.Deserialisable, _common.Serialisable): """Workflow type identifier.""" name: str @@ -23,7 +23,7 @@ class WorkflowId(_common.Deserialisable, _common.Serialisable): """Workflow version.""" @classmethod - def from_api(cls, data) -> "WorkflowId": + def from_api(cls, data) -> "WorkflowTypeReference": return cls(data["name"], data["version"]) def to_api(self): @@ -31,10 +31,10 @@ def to_api(self): @dataclasses.dataclass -class WorkflowInfo(_common.Deserialisable): +class WorkflowTypeInfo(_common.Deserialisable): """Workflow type details.""" - workflow: WorkflowId + workflow_type: WorkflowTypeReference """Workflow ID.""" is_deprecated: bool @@ -50,9 +50,9 @@ class WorkflowInfo(_common.Deserialisable): """Deprecation date.""" @classmethod - def from_api(cls, data) -> "WorkflowInfo": + def from_api(cls, data) -> "WorkflowTypeInfo": return cls( - workflow=WorkflowId.from_api(data["workflowType"]), + workflow_type=WorkflowTypeReference.from_api(data["workflowType"]), is_deprecated=_common.is_deprecated_by_registration_status[data["status"]], created=data["creationDate"], description=data.get("description"), @@ -74,26 +74,26 @@ def get_api_args(self): @dataclasses.dataclass -class WorkflowDetails(_common.Deserialisable): +class WorkflowTypeDetails(_common.Deserialisable): """Workflow type details and default workflow execution configuration.""" - info: WorkflowInfo + info: WorkflowTypeInfo """Workflow details.""" default_execution_configuration: DefaultExecutionConfiguration """Default execution configuration, can be overriden when starting.""" @classmethod - def from_api(cls, data) -> "WorkflowDetails": + def from_api(cls, data) -> "WorkflowTypeDetails": configuration = DefaultExecutionConfiguration.from_api(data) return cls( - info=WorkflowInfo.from_api(data["typeInfo"]), + info=WorkflowTypeInfo.from_api(data["typeInfo"]), default_execution_configuration=configuration, ) @dataclasses.dataclass -class WorkflowIdFilter(_common.Serialisable, _common.SerialisableToArguments): +class WorkflowTypeFilter(_common.Serialisable, _common.SerialisableToArguments): """Workflow type filter on workflow name.""" name: str @@ -106,49 +106,49 @@ def get_api_args(self): return {"name": self.name} -def delete_workflow( - workflow: WorkflowId, +def delete_workflow_type( + workflow_type: WorkflowTypeReference, domain: str, client: "botocore.client.BaseClient" = None, ) -> None: """Delete a (deprecated/inactive) workflow type. Args: - workflow: workflow type to delete + workflow_type: workflow type to delete domain: domain of workflow type client: SWF client """ client = _common.ensure_client(client) - client.delete_workflow_type(domain=domain, workflowType=workflow.to_api()) + client.delete_workflow_type(domain=domain, workflowType=workflow_type.to_api()) -def deprecate_workflow( - workflow: WorkflowId, +def deprecate_workflow_type( + workflow_type: WorkflowTypeReference, domain: str, client: "botocore.client.BaseClient" = None, ) -> None: """Deprecate (deactivate) a workflow type. Args: - workflow: workflow type to deprecate + workflow_type: workflow type to deprecate domain: domain of workflow type client: SWF client """ client = _common.ensure_client(client) - client.deprecate_workflow_type(domain=domain, workflowType=workflow.to_api()) + client.deprecate_workflow_type(domain=domain, workflowType=workflow_type.to_api()) -def describe_workflow( - workflow: WorkflowId, +def describe_workflow_type( + workflow_type: WorkflowTypeReference, domain: str, client: "botocore.client.BaseClient" = None, -) -> WorkflowDetails: +) -> WorkflowTypeDetails: """Describe a workflow type. Args: - workflow: workflow type to describe + workflow_type: workflow type to describe domain: domain of workflow type client: SWF client @@ -158,25 +158,25 @@ def describe_workflow( client = _common.ensure_client(client) response = client.describe_workflow_type( - domain=domain, workflowType=workflow.to_api() + domain=domain, workflowType=workflow_type.to_api() ) - return WorkflowDetails.from_api(response) + return WorkflowTypeDetails.from_api(response) -def list_workflows( +def list_workflow_types( domain: str, deprecated: bool = False, - workflow_filter: WorkflowIdFilter = None, + workflow_type_filter: WorkflowTypeFilter = None, reverse: bool = False, client: "botocore.client.BaseClient" = None, -) -> t.Generator[WorkflowInfo, None, None]: +) -> t.Generator[WorkflowTypeInfo, None, None]: """List workflow types; retrieved semi-lazily. Args: domain: domain of workflow types deprecated: list deprecated workflow types instead of non-deprecated - workflow_filter: filter returned workflow types by name + workflow_type_filter: filter returned workflow types by name reverse: return results in reverse alphabetical order client: SWF client @@ -186,8 +186,8 @@ def list_workflows( client = _common.ensure_client(client) kw = {} - if workflow_filter: - kw.update(workflow_filter.get_api_args()) + if workflow_type_filter: + kw.update(workflow_type_filter.get_api_args()) call = functools.partial( client.list_workflow_types, domain=domain, @@ -195,11 +195,11 @@ def list_workflows( reverseOrder=reverse, **kw, ) - return _common.iter_paged(call, WorkflowInfo.from_api, "typeInfos") + return _common.iter_paged(call, WorkflowTypeInfo.from_api, "typeInfos") -def register_workflow( - workflow: WorkflowId, +def register_workflow_type( + workflow_type: WorkflowTypeReference, domain: str, description: str = None, default_execution_configuration: DefaultExecutionConfiguration = None, @@ -208,7 +208,7 @@ def register_workflow( """Register a new workflow type. Args: - workflow: workflow type name and version + workflow_type: workflow type name and version domain: domain to register in description: workflow type description default_execution_configuration: default configuration for workflow @@ -225,24 +225,24 @@ def register_workflow( kw["description"] = description client.register_workflow_type( domain=domain, - name=workflow.name, - version=workflow.version, + name=workflow_type.name, + version=workflow_type.version, **kw, ) -def undeprecate_workflow( - workflow: WorkflowId, +def undeprecate_workflow_type( + workflow_type: WorkflowTypeReference, domain: str, client: "botocore.client.BaseClient" = None, ) -> None: """Undeprecate (reactivate) a workflow type. Args: - workflow: workflow type to undeprecate + workflow_type: workflow type to undeprecate domain: domain of workflow type client: SWF client """ client = _common.ensure_client(client) - client.undeprecate_workflow_type(domain=domain, workflowType=workflow.to_api()) + client.undeprecate_workflow_type(domain=domain, workflowType=workflow_type.to_api())