Skip to content

Commit 0ea5751

Browse files
author
Alan Christie
committed
refactor: Change APIAdapter name and general housekeeping (and Python 3.13)
1 parent b101f3f commit 0ea5751

9 files changed

+77
-86
lines changed

poetry.lock

Lines changed: 5 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "im-data-manager-workflow-engine"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
description = "The Data Manager workflow engine, schema and decoder."
55
authors = [
66
"Alan Christie <[email protected]>",
@@ -12,7 +12,7 @@ packages = [
1212
]
1313

1414
[tool.poetry.dependencies]
15-
python = "^3.12"
15+
python = "^3.13"
1616
im-protobuf = "^8.2.0"
1717
im-data-manager-job-decoder = "^2.1.0"
1818
jsonschema = "^4.21.1"

tests/api_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import yaml
2424

25-
from workflow.workflow_abc import APIAdapter
25+
from workflow.workflow_abc import WorkflowAPIAdapter
2626

2727
# Load the Unit test Job Definitions file now.
2828
_JOB_DEFINITION_FILE: str = os.path.join(
@@ -52,7 +52,7 @@
5252
_TASK_PICKLE_FILE: str = f"{_PICKLE_DIRECTORY}/task.pickle"
5353

5454

55-
class UnitTestAPIAdapter(APIAdapter):
55+
class UnitTestAPIAdapter(WorkflowAPIAdapter):
5656
"""A minimal API adapter. It serves-up Job Definitions
5757
from the job-definitions/job-definitions.yaml file and provides basic
5858
storage for Workflow Definitions and related tables.

tests/test_worflow_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def basic_validator():
1616
api_adapter = UnitTestAPIAdapter()
1717
msg_queue = UnitTestMessageQueue()
1818
msg_dispatcher = UnitTestMessageDispatcher(msg_queue=msg_queue)
19-
return WorkflowValidator(api_adapter=api_adapter, msg_dispatcher=msg_dispatcher)
19+
return WorkflowValidator(wapi_adapter=api_adapter, msg_dispatcher=msg_dispatcher)
2020

2121

2222
def test_validate_minimal_for_create(basic_validator):

tests/test_workflow_engine_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def basic_engine():
2626
api_adapter=api_adapter, msg_dispatcher=message_dispatcher
2727
)
2828
workflow_engine = WorkflowEngine(
29-
api_adapter=api_adapter, instance_launcher=instance_launcher
29+
wapi_adapter=api_adapter, instance_launcher=instance_launcher
3030
)
3131
message_queue.set_receiver(workflow_engine.handle_message)
3232
print("Starting message queue...")

workflow/decoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
import os
7-
from typing import Any, Dict, Optional
7+
from typing import Any
88

99
import jsonschema
1010
import yaml
@@ -19,11 +19,11 @@
1919
# This must work as the file is installed along with this module.
2020
assert os.path.isfile(_WORKFLOW_SCHEMA_FILE)
2121
with open(_WORKFLOW_SCHEMA_FILE, "r", encoding="utf8") as schema_file:
22-
_WORKFLOW_SCHEMA: Dict[str, Any] = yaml.load(schema_file, Loader=yaml.FullLoader)
22+
_WORKFLOW_SCHEMA: dict[str, Any] = yaml.load(schema_file, Loader=yaml.FullLoader)
2323
assert _WORKFLOW_SCHEMA
2424

2525

26-
def validate_schema(workflow: Dict[str, Any]) -> Optional[str]:
26+
def validate_schema(workflow: dict[str, Any]) -> str | None:
2727
"""Checks the Workflow Definition against the built-in schema.
2828
If there's an error the error text is returned, otherwise None.
2929
"""

workflow/workflow_abc.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Workflow abstract base classes.
2-
Interface definitions of class instances that must be provided to the Engine.
2+
Interface definitions of class instances that must be made available to the Engine.
33
"""
44

55
from abc import ABC, abstractmethod
66
from dataclasses import dataclass
7-
from typing import Any, Dict, List, Optional
7+
from typing import Any
88

99
from google.protobuf.message import Message
1010

@@ -14,10 +14,10 @@ class LaunchResult:
1414
"""Results returned from methods in the InstanceLauncher."""
1515

1616
error: int
17-
error_msg: Optional[str]
18-
instance_id: Optional[str]
19-
task_id: Optional[str]
20-
command: Optional[str]
17+
error_msg: str | None
18+
instance_id: str | None
19+
task_id: str | None
20+
command: str | None
2121

2222

2323
class InstanceLauncher(ABC):
@@ -31,7 +31,7 @@ def launch(
3131
running_workflow_id: str,
3232
running_workflow_step_id: str,
3333
step_specification: str,
34-
variables: Dict[str, Any],
34+
variables: dict[str, Any],
3535
) -> LaunchResult:
3636
"""Launch a (Job) Instance"""
3737

@@ -48,17 +48,18 @@ def launch(
4848
# See _instance_preamble() in the DM's api_instance.py module.
4949

5050

51-
class APIAdapter(ABC):
52-
"""The APIAdapter providing read/write access to the Model. It provides
53-
the ability to create and retrieve Workflow, RunningWorkflow and RunningWorkflowStep
54-
records returning dictionary (API-like) responses."""
51+
class WorkflowAPIAdapter(ABC):
52+
"""The APIAdapter providing read/write access to various Workflow tables and records
53+
in the Model that is owned by the DM. It provides the ability to create and retrieve
54+
Workflow, RunningWorkflow and RunningWorkflowStep records returning dictionary
55+
(API-like) responses."""
5556

5657
@abstractmethod
5758
def create_workflow(
5859
self,
5960
*,
60-
workflow_definition: Dict[str, Any],
61-
) -> Dict[str, Any]:
61+
workflow_definition: dict[str, Any],
62+
) -> dict[str, Any]:
6263
"""Create a Workflow, getting an ID in return"""
6364
# Should return:
6465
# {
@@ -70,7 +71,7 @@ def get_workflow(
7071
self,
7172
*,
7273
workflow_id: str,
73-
) -> Dict[str, Any]:
74+
) -> dict[str, Any]:
7475
"""Get a Workflow Record by ID."""
7576
# If present this should return:
7677
# {
@@ -83,7 +84,7 @@ def get_workflow_by_name(
8384
*,
8485
name: str,
8586
version: str,
86-
) -> Dict[str, Any]:
87+
) -> dict[str, Any]:
8788
"""Get a Workflow Record by name"""
8889
# If present this should return:
8990
# {
@@ -97,9 +98,9 @@ def create_running_workflow(
9798
*,
9899
workflow_id: str,
99100
project_id: str,
100-
variables: Dict[str, Any],
101+
variables: dict[str, Any],
101102
user_id: str,
102-
) -> Dict[str, Any]:
103+
) -> dict[str, Any]:
103104
"""Create a RunningWorkflow Record (from a Workflow)"""
104105
# Should return:
105106
# {
@@ -112,14 +113,14 @@ def set_running_workflow_done(
112113
*,
113114
running_workflow_id: str,
114115
success: bool,
115-
error: Optional[int] = None,
116-
error_msg: Optional[str] = None,
116+
error: int | None = None,
117+
error_msg: str | None = None,
117118
) -> None:
118119
"""Set the success value for a RunningWorkflow Record.
119120
If not successful an error code and message should be provided."""
120121

121122
@abstractmethod
122-
def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
123+
def get_running_workflow(self, *, running_workflow_id: str) -> dict[str, Any]:
123124
"""Get a RunningWorkflow Record"""
124125
# Should return:
125126
# {
@@ -141,7 +142,7 @@ def create_running_workflow_step(
141142
*,
142143
running_workflow_id: str,
143144
step: str,
144-
) -> Dict[str, Any]:
145+
) -> dict[str, Any]:
145146
"""Create a RunningWorkflowStep Record (from a RunningWorkflow)"""
146147
# Should return:
147148
# {
@@ -151,7 +152,7 @@ def create_running_workflow_step(
151152
@abstractmethod
152153
def get_running_workflow_step(
153154
self, *, running_workflow_step_id: str
154-
) -> Dict[str, Any]:
155+
) -> dict[str, Any]:
155156
"""Get a RunningWorkflowStep Record"""
156157
# Should return:
157158
# {
@@ -171,16 +172,16 @@ def set_running_workflow_step_done(
171172
*,
172173
running_workflow_step_id: str,
173174
success: bool,
174-
error: Optional[int] = None,
175-
error_msg: Optional[str] = None,
175+
error: int | None = None,
176+
error_msg: str | None = None,
176177
) -> None:
177178
"""Set the success value for a RunningWorkflowStep Record,
178179
If not successful an error code and message should be provided."""
179180

180181
@abstractmethod
181182
def get_running_workflow_steps(
182183
self, *, running_workflow_id: str
183-
) -> List[Dict[str, Any]]:
184+
) -> list[dict[str, Any]]:
184185
"""Gets all the RunningWorkflowStep Records (for a RunningWorkflow)"""
185186
# Should return:
186187
# {
@@ -201,7 +202,7 @@ def get_running_workflow_steps(
201202
# }
202203

203204
@abstractmethod
204-
def create_instance(self, running_workflow_step_id: str) -> Dict[str, Any]:
205+
def create_instance(self, running_workflow_step_id: str) -> dict[str, Any]:
205206
"""Create an Instance Record (for a RunningWorkflowStep)"""
206207
# Should return:
207208
# {
@@ -210,7 +211,7 @@ def create_instance(self, running_workflow_step_id: str) -> Dict[str, Any]:
210211
# }
211212

212213
@abstractmethod
213-
def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
214+
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
214215
"""Get an Instance Record"""
215216
# Should return:
216217
# {
@@ -219,15 +220,15 @@ def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
219220
# }
220221

221222
@abstractmethod
222-
def create_task(self, instance_id: str) -> Dict[str, Any]:
223-
"""Create a Task Record (for amn Instance)"""
223+
def create_task(self, instance_id: str) -> dict[str, Any]:
224+
"""Create a Task Record (for an Instance)"""
224225
# Should return:
225226
# {
226227
# "id": "task-00000000-0000-0000-0000-000000000001",
227228
# }
228229

229230
@abstractmethod
230-
def get_task(self, *, task_id: str) -> Dict[str, Any]:
231+
def get_task(self, *, task_id: str) -> dict[str, Any]:
231232
"""Get a Task Record"""
232233
# Should return:
233234
# {
@@ -243,7 +244,7 @@ def get_job(
243244
collection: str,
244245
job: str,
245246
version: str,
246-
) -> Optional[Dict[str, Any]]:
247+
) -> dict[str, Any] | None:
247248
"""Get a Job"""
248249

249250

0 commit comments

Comments
 (0)