1
1
"""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.
3
3
"""
4
4
5
5
from abc import ABC , abstractmethod
6
6
from dataclasses import dataclass
7
- from typing import Any , Dict , List , Optional
7
+ from typing import Any
8
8
9
9
from google .protobuf .message import Message
10
10
@@ -14,10 +14,10 @@ class LaunchResult:
14
14
"""Results returned from methods in the InstanceLauncher."""
15
15
16
16
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
21
21
22
22
23
23
class InstanceLauncher (ABC ):
@@ -31,7 +31,7 @@ def launch(
31
31
running_workflow_id : str ,
32
32
running_workflow_step_id : str ,
33
33
step_specification : str ,
34
- variables : Dict [str , Any ],
34
+ variables : dict [str , Any ],
35
35
) -> LaunchResult :
36
36
"""Launch a (Job) Instance"""
37
37
@@ -48,17 +48,18 @@ def launch(
48
48
# See _instance_preamble() in the DM's api_instance.py module.
49
49
50
50
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."""
55
56
56
57
@abstractmethod
57
58
def create_workflow (
58
59
self ,
59
60
* ,
60
- workflow_definition : Dict [str , Any ],
61
- ) -> Dict [str , Any ]:
61
+ workflow_definition : dict [str , Any ],
62
+ ) -> dict [str , Any ]:
62
63
"""Create a Workflow, getting an ID in return"""
63
64
# Should return:
64
65
# {
@@ -70,7 +71,7 @@ def get_workflow(
70
71
self ,
71
72
* ,
72
73
workflow_id : str ,
73
- ) -> Dict [str , Any ]:
74
+ ) -> dict [str , Any ]:
74
75
"""Get a Workflow Record by ID."""
75
76
# If present this should return:
76
77
# {
@@ -83,7 +84,7 @@ def get_workflow_by_name(
83
84
* ,
84
85
name : str ,
85
86
version : str ,
86
- ) -> Dict [str , Any ]:
87
+ ) -> dict [str , Any ]:
87
88
"""Get a Workflow Record by name"""
88
89
# If present this should return:
89
90
# {
@@ -97,9 +98,9 @@ def create_running_workflow(
97
98
* ,
98
99
workflow_id : str ,
99
100
project_id : str ,
100
- variables : Dict [str , Any ],
101
+ variables : dict [str , Any ],
101
102
user_id : str ,
102
- ) -> Dict [str , Any ]:
103
+ ) -> dict [str , Any ]:
103
104
"""Create a RunningWorkflow Record (from a Workflow)"""
104
105
# Should return:
105
106
# {
@@ -112,14 +113,14 @@ def set_running_workflow_done(
112
113
* ,
113
114
running_workflow_id : str ,
114
115
success : bool ,
115
- error : Optional [ int ] = None ,
116
- error_msg : Optional [ str ] = None ,
116
+ error : int | None = None ,
117
+ error_msg : str | None = None ,
117
118
) -> None :
118
119
"""Set the success value for a RunningWorkflow Record.
119
120
If not successful an error code and message should be provided."""
120
121
121
122
@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 ]:
123
124
"""Get a RunningWorkflow Record"""
124
125
# Should return:
125
126
# {
@@ -141,7 +142,7 @@ def create_running_workflow_step(
141
142
* ,
142
143
running_workflow_id : str ,
143
144
step : str ,
144
- ) -> Dict [str , Any ]:
145
+ ) -> dict [str , Any ]:
145
146
"""Create a RunningWorkflowStep Record (from a RunningWorkflow)"""
146
147
# Should return:
147
148
# {
@@ -151,7 +152,7 @@ def create_running_workflow_step(
151
152
@abstractmethod
152
153
def get_running_workflow_step (
153
154
self , * , running_workflow_step_id : str
154
- ) -> Dict [str , Any ]:
155
+ ) -> dict [str , Any ]:
155
156
"""Get a RunningWorkflowStep Record"""
156
157
# Should return:
157
158
# {
@@ -171,16 +172,16 @@ def set_running_workflow_step_done(
171
172
* ,
172
173
running_workflow_step_id : str ,
173
174
success : bool ,
174
- error : Optional [ int ] = None ,
175
- error_msg : Optional [ str ] = None ,
175
+ error : int | None = None ,
176
+ error_msg : str | None = None ,
176
177
) -> None :
177
178
"""Set the success value for a RunningWorkflowStep Record,
178
179
If not successful an error code and message should be provided."""
179
180
180
181
@abstractmethod
181
182
def get_running_workflow_steps (
182
183
self , * , running_workflow_id : str
183
- ) -> List [ Dict [str , Any ]]:
184
+ ) -> list [ dict [str , Any ]]:
184
185
"""Gets all the RunningWorkflowStep Records (for a RunningWorkflow)"""
185
186
# Should return:
186
187
# {
@@ -201,7 +202,7 @@ def get_running_workflow_steps(
201
202
# }
202
203
203
204
@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 ]:
205
206
"""Create an Instance Record (for a RunningWorkflowStep)"""
206
207
# Should return:
207
208
# {
@@ -210,7 +211,7 @@ def create_instance(self, running_workflow_step_id: str) -> Dict[str, Any]:
210
211
# }
211
212
212
213
@abstractmethod
213
- def get_instance (self , * , instance_id : str ) -> Dict [str , Any ]:
214
+ def get_instance (self , * , instance_id : str ) -> dict [str , Any ]:
214
215
"""Get an Instance Record"""
215
216
# Should return:
216
217
# {
@@ -219,15 +220,15 @@ def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
219
220
# }
220
221
221
222
@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)"""
224
225
# Should return:
225
226
# {
226
227
# "id": "task-00000000-0000-0000-0000-000000000001",
227
228
# }
228
229
229
230
@abstractmethod
230
- def get_task (self , * , task_id : str ) -> Dict [str , Any ]:
231
+ def get_task (self , * , task_id : str ) -> dict [str , Any ]:
231
232
"""Get a Task Record"""
232
233
# Should return:
233
234
# {
@@ -243,7 +244,7 @@ def get_job(
243
244
collection : str ,
244
245
job : str ,
245
246
version : str ,
246
- ) -> Optional [ Dict [ str , Any ]] :
247
+ ) -> dict [ str , Any ] | None :
247
248
"""Get a Job"""
248
249
249
250
0 commit comments