Skip to content

Commit aeaae42

Browse files
author
Alan Christie
committed
style: API Adapter no longer required create instance/task (these are internal to instance launcher)
1 parent 217394a commit aeaae42

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

tests/instance_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def launch(self, launch_parameters: LaunchParameters) -> LaunchResult:
8080
running_workflow_step_id=launch_parameters.running_workflow_step_id
8181
)
8282
instance_id = response["id"]
83-
response = self._api_adapter.create_task(instance_id=instance_id)
83+
response = self._api_adapter.create_task()
8484
task_id = response["id"]
8585

8686
# Apply variables to the step's Job command.

tests/test_test_api_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def test_create_task():
272272
utaa = UnitTestWorkflowAPIAdapter()
273273

274274
# Act
275-
response = utaa.create_task(instance_id="instance-000")
275+
response = utaa.create_task()
276276

277277
# Assert
278278
assert "id" in response
@@ -281,7 +281,7 @@ def test_create_task():
281281
def test_create_and_get_task():
282282
# Arrange
283283
utaa = UnitTestWorkflowAPIAdapter()
284-
response = utaa.create_task(instance_id="instance-000")
284+
response = utaa.create_task()
285285
task_id = response["id"]
286286

287287
# Act

tests/wapi_adapter.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,36 @@ def get_running_workflow_steps(self, *, running_workflow_id: str) -> dict[str, A
243243
steps.append(item)
244244
return {"count": len(steps), "running_workflow_steps": steps}
245245

246+
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
247+
UnitTestWorkflowAPIAdapter.lock.acquire()
248+
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
249+
instances = Unpickler(pickle_file).load()
250+
UnitTestWorkflowAPIAdapter.lock.release()
251+
252+
return {} if instance_id not in instances else instances[instance_id]
253+
254+
def get_task(self, *, task_id: str) -> dict[str, Any]:
255+
UnitTestWorkflowAPIAdapter.lock.acquire()
256+
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
257+
tasks = Unpickler(pickle_file).load()
258+
UnitTestWorkflowAPIAdapter.lock.release()
259+
260+
return {} if task_id not in tasks else tasks[task_id]
261+
262+
def get_job(self, *, collection: str, job: str, version: str) -> dict[str, Any]:
263+
assert collection == _JOB_DEFINITIONS["collection"]
264+
assert job in _JOB_DEFINITIONS["jobs"]
265+
assert version
266+
267+
jd = _JOB_DEFINITIONS["jobs"][job]
268+
response = {"command": jd["command"]}
269+
if "variables" in jd:
270+
response["variables"] = jd["variables"]
271+
return response
272+
273+
# Methods required for the UnitTestInstanceLauncher
274+
# but not exposed to (or required by) the Workflow Engine...
275+
246276
def create_instance(self, *, running_workflow_step_id: str) -> dict[str, Any]:
247277
UnitTestWorkflowAPIAdapter.lock.acquire()
248278
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
@@ -261,15 +291,7 @@ def create_instance(self, *, running_workflow_step_id: str) -> dict[str, Any]:
261291

262292
return {"id": instance_id}
263293

264-
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
265-
UnitTestWorkflowAPIAdapter.lock.acquire()
266-
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
267-
instances = Unpickler(pickle_file).load()
268-
UnitTestWorkflowAPIAdapter.lock.release()
269-
270-
return {} if instance_id not in instances else instances[instance_id]
271-
272-
def create_task(self, *, instance_id: str) -> dict[str, Any]:
294+
def create_task(self) -> dict[str, Any]:
273295
UnitTestWorkflowAPIAdapter.lock.acquire()
274296
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
275297
tasks = Unpickler(pickle_file).load()
@@ -287,22 +309,3 @@ def create_task(self, *, instance_id: str) -> dict[str, Any]:
287309
UnitTestWorkflowAPIAdapter.lock.release()
288310

289311
return {"id": task_id}
290-
291-
def get_task(self, *, task_id: str) -> dict[str, Any]:
292-
UnitTestWorkflowAPIAdapter.lock.acquire()
293-
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
294-
tasks = Unpickler(pickle_file).load()
295-
UnitTestWorkflowAPIAdapter.lock.release()
296-
297-
return {} if task_id not in tasks else tasks[task_id]
298-
299-
def get_job(self, *, collection: str, job: str, version: str) -> dict[str, Any]:
300-
assert collection == _JOB_DEFINITIONS["collection"]
301-
assert job in _JOB_DEFINITIONS["jobs"]
302-
assert version
303-
304-
jd = _JOB_DEFINITIONS["jobs"][job]
305-
response = {"command": jd["command"]}
306-
if "variables" in jd:
307-
response["variables"] = jd["variables"]
308-
return response

workflow/workflow_abc.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,6 @@ def get_running_workflow_steps(self, *, running_workflow_id: str) -> dict[str, A
210210
# }
211211
# If there are not steps an empty dictionary should be returned and a count of 0
212212

213-
@abstractmethod
214-
def create_instance(self, running_workflow_step_id: str) -> dict[str, Any]:
215-
"""Create an Instance Record (for a RunningWorkflowStep)"""
216-
# Should return:
217-
# {
218-
# "instance_id": "instance-00000000-0000-0000-0000-000000000001",
219-
# "task_id": "task-00000000-0000-0000-0000-000000000001",
220-
# }
221-
222213
@abstractmethod
223214
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
224215
"""Get an Instance Record"""
@@ -229,14 +220,6 @@ def get_instance(self, *, instance_id: str) -> dict[str, Any]:
229220
# }
230221
# If not present an empty dictionary should be returned.
231222

232-
@abstractmethod
233-
def create_task(self, instance_id: str) -> dict[str, Any]:
234-
"""Create a Task Record (for an Instance)"""
235-
# Should return:
236-
# {
237-
# "id": "task-00000000-0000-0000-0000-000000000001",
238-
# }
239-
240223
@abstractmethod
241224
def get_task(self, *, task_id: str) -> dict[str, Any]:
242225
"""Get a Task Record"""

0 commit comments

Comments
 (0)