52
52
_TASK_PICKLE_FILE : str = f"{ _PICKLE_DIRECTORY } /task.pickle"
53
53
54
54
55
- class UnitTestAPIAdapter (WorkflowAPIAdapter ):
55
+ class UnitTestWorkflowAPIAdapter (WorkflowAPIAdapter ):
56
56
"""A minimal API adapter. It serves-up Job Definitions
57
57
from the job-definitions/job-definitions.yaml file and provides basic
58
58
storage for Workflow Definitions and related tables.
@@ -66,7 +66,7 @@ class UnitTestAPIAdapter(WorkflowAPIAdapter):
66
66
def __init__ (self ):
67
67
super ().__init__ ()
68
68
# Safely initialise the pickle files
69
- UnitTestAPIAdapter .lock .acquire ()
69
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
70
70
if not os .path .exists (_PICKLE_DIRECTORY ):
71
71
os .makedirs (_PICKLE_DIRECTORY )
72
72
for file in [
@@ -78,10 +78,10 @@ def __init__(self):
78
78
]:
79
79
with open (file , "wb" ) as pickle_file :
80
80
Pickler (pickle_file ).dump ({})
81
- UnitTestAPIAdapter .lock .release ()
81
+ UnitTestWorkflowAPIAdapter .lock .release ()
82
82
83
83
def create_workflow (self , * , workflow_definition : Dict [str , Any ]) -> str :
84
- UnitTestAPIAdapter .lock .acquire ()
84
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
85
85
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
86
86
workflow = Unpickler (pickle_file ).load ()
87
87
@@ -91,23 +91,23 @@ def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
91
91
92
92
with open (_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
93
93
Pickler (pickle_file ).dump (workflow )
94
- UnitTestAPIAdapter .lock .release ()
94
+ UnitTestWorkflowAPIAdapter .lock .release ()
95
95
96
96
return {"id" : workflow_definition_id }
97
97
98
98
def get_workflow (self , * , workflow_id : str ) -> Dict [str , Any ]:
99
- UnitTestAPIAdapter .lock .acquire ()
99
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
100
100
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
101
101
workflow = Unpickler (pickle_file ).load ()
102
- UnitTestAPIAdapter .lock .release ()
102
+ UnitTestWorkflowAPIAdapter .lock .release ()
103
103
104
104
return {"workflow" : workflow [workflow_id ]} if workflow_id in workflow else {}
105
105
106
106
def get_workflow_by_name (self , * , name : str , version : str ) -> Dict [str , Any ]:
107
- UnitTestAPIAdapter .lock .acquire ()
107
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
108
108
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
109
109
workflow = Unpickler (pickle_file ).load ()
110
- UnitTestAPIAdapter .lock .release ()
110
+ UnitTestWorkflowAPIAdapter .lock .release ()
111
111
112
112
item = {}
113
113
for wfid , value in workflow .items ():
@@ -126,7 +126,7 @@ def create_running_workflow(
126
126
assert user_id
127
127
assert isinstance (variables , dict )
128
128
129
- UnitTestAPIAdapter .lock .acquire ()
129
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
130
130
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
131
131
running_workflow = Unpickler (pickle_file ).load ()
132
132
@@ -144,7 +144,7 @@ def create_running_workflow(
144
144
145
145
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
146
146
Pickler (pickle_file ).dump (running_workflow )
147
- UnitTestAPIAdapter .lock .release ()
147
+ UnitTestWorkflowAPIAdapter .lock .release ()
148
148
149
149
return {"id" : running_workflow_id }
150
150
@@ -156,7 +156,7 @@ def set_running_workflow_done(
156
156
error : Optional [int ] = None ,
157
157
error_msg : Optional [str ] = None ,
158
158
) -> None :
159
- UnitTestAPIAdapter .lock .acquire ()
159
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
160
160
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
161
161
running_workflow = Unpickler (pickle_file ).load ()
162
162
@@ -168,13 +168,13 @@ def set_running_workflow_done(
168
168
169
169
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
170
170
Pickler (pickle_file ).dump (running_workflow )
171
- UnitTestAPIAdapter .lock .release ()
171
+ UnitTestWorkflowAPIAdapter .lock .release ()
172
172
173
173
def get_running_workflow (self , * , running_workflow_id : str ) -> Dict [str , Any ]:
174
- UnitTestAPIAdapter .lock .acquire ()
174
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
175
175
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
176
176
running_workflow = Unpickler (pickle_file ).load ()
177
- UnitTestAPIAdapter .lock .release ()
177
+ UnitTestWorkflowAPIAdapter .lock .release ()
178
178
179
179
if running_workflow_id not in running_workflow :
180
180
return {}
@@ -183,7 +183,7 @@ def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
183
183
def create_running_workflow_step (
184
184
self , * , running_workflow_id : str , step : str
185
185
) -> str :
186
- UnitTestAPIAdapter .lock .acquire ()
186
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
187
187
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
188
188
running_workflow_step = Unpickler (pickle_file ).load ()
189
189
@@ -201,17 +201,17 @@ def create_running_workflow_step(
201
201
202
202
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "wb" ) as pickle_file :
203
203
Pickler (pickle_file ).dump (running_workflow_step )
204
- UnitTestAPIAdapter .lock .release ()
204
+ UnitTestWorkflowAPIAdapter .lock .release ()
205
205
206
206
return {"id" : running_workflow_step_id }
207
207
208
208
def get_running_workflow_step (
209
209
self , * , running_workflow_step_id : str
210
210
) -> Dict [str , Any ]:
211
- UnitTestAPIAdapter .lock .acquire ()
211
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
212
212
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
213
213
running_workflow_step = Unpickler (pickle_file ).load ()
214
- UnitTestAPIAdapter .lock .release ()
214
+ UnitTestWorkflowAPIAdapter .lock .release ()
215
215
216
216
if running_workflow_step_id not in running_workflow_step :
217
217
return {}
@@ -227,7 +227,7 @@ def set_running_workflow_step_done(
227
227
error : Optional [int ] = None ,
228
228
error_msg : Optional [str ] = None ,
229
229
) -> None :
230
- UnitTestAPIAdapter .lock .acquire ()
230
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
231
231
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
232
232
running_workflow_step = Unpickler (pickle_file ).load ()
233
233
@@ -239,15 +239,15 @@ def set_running_workflow_step_done(
239
239
240
240
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "wb" ) as pickle_file :
241
241
Pickler (pickle_file ).dump (running_workflow_step )
242
- UnitTestAPIAdapter .lock .release ()
242
+ UnitTestWorkflowAPIAdapter .lock .release ()
243
243
244
244
def get_running_workflow_steps (
245
245
self , * , running_workflow_id : str
246
246
) -> List [Dict [str , Any ]]:
247
- UnitTestAPIAdapter .lock .acquire ()
247
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
248
248
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
249
249
running_workflow_step = Unpickler (pickle_file ).load ()
250
- UnitTestAPIAdapter .lock .release ()
250
+ UnitTestWorkflowAPIAdapter .lock .release ()
251
251
252
252
steps = []
253
253
for key , value in running_workflow_step .items ():
@@ -257,7 +257,7 @@ def get_running_workflow_steps(
257
257
return {"count" : len (steps ), "running_workflow_steps" : steps }
258
258
259
259
def create_instance (self , * , running_workflow_step_id : str ) -> Dict [str , Any ]:
260
- UnitTestAPIAdapter .lock .acquire ()
260
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
261
261
with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
262
262
instances = Unpickler (pickle_file ).load ()
263
263
@@ -270,20 +270,20 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
270
270
271
271
with open (_INSTANCE_PICKLE_FILE , "wb" ) as pickle_file :
272
272
Pickler (pickle_file ).dump (instances )
273
- UnitTestAPIAdapter .lock .release ()
273
+ UnitTestWorkflowAPIAdapter .lock .release ()
274
274
275
275
return {"id" : instance_id }
276
276
277
277
def get_instance (self , * , instance_id : str ) -> Dict [str , Any ]:
278
- UnitTestAPIAdapter .lock .acquire ()
278
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
279
279
with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
280
280
instances = Unpickler (pickle_file ).load ()
281
- UnitTestAPIAdapter .lock .release ()
281
+ UnitTestWorkflowAPIAdapter .lock .release ()
282
282
283
283
return {} if instance_id not in instances else instances [instance_id ]
284
284
285
285
def create_task (self , * , instance_id : str ) -> Dict [str , Any ]:
286
- UnitTestAPIAdapter .lock .acquire ()
286
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
287
287
with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
288
288
tasks = Unpickler (pickle_file ).load ()
289
289
@@ -297,15 +297,15 @@ def create_task(self, *, instance_id: str) -> Dict[str, Any]:
297
297
298
298
with open (_TASK_PICKLE_FILE , "wb" ) as pickle_file :
299
299
Pickler (pickle_file ).dump (tasks )
300
- UnitTestAPIAdapter .lock .release ()
300
+ UnitTestWorkflowAPIAdapter .lock .release ()
301
301
302
302
return {"id" : task_id }
303
303
304
304
def get_task (self , * , task_id : str ) -> Dict [str , Any ]:
305
- UnitTestAPIAdapter .lock .acquire ()
305
+ UnitTestWorkflowAPIAdapter .lock .acquire ()
306
306
with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
307
307
tasks = Unpickler (pickle_file ).load ()
308
- UnitTestAPIAdapter .lock .release ()
308
+ UnitTestWorkflowAPIAdapter .lock .release ()
309
309
310
310
return {} if task_id not in tasks else tasks [task_id ]
311
311
0 commit comments