Skip to content

Commit 9822f9b

Browse files
author
Alan Christie
committed
feat: API adapter now handles tasks
1 parent c5aaf30 commit 9822f9b

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

tests/api_adapter.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self):
3333
self._running_workflow: Dict[str, Dict[str, Any]] = {}
3434
self._running_workflow_steps: Dict[str, Dict[str, Any]] = {}
3535
self._instances: Dict[str, Dict[str, Any]] = {}
36+
self._tasks: Dict[str, Dict[str, Any]] = {}
3637

3738
def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
3839
next_id: int = len(self._workflow_definitions) + 1
@@ -108,13 +109,29 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
108109
"running_workflow_step": running_workflow_step_id,
109110
}
110111
self._instances[instance_id] = record
111-
return {"instance_id": running_workflow_step_id}
112+
return {"id": running_workflow_step_id}
112113

113114
def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
114115
if instance_id not in self._instances:
115116
return {}
116117
return {self._instances[instance_id]}
117118

119+
def create_task(self, *, instance_id: str) -> Dict[str, Any]:
120+
next_id: int = len(self._instances) + 1
121+
task_id: str = _INSTANCE_ID_FORMAT.format(id=next_id)
122+
record = {
123+
"instance_id": instance_id,
124+
"done": False,
125+
"exit_code": 0,
126+
}
127+
self._tasks[task_id] = record
128+
return {"id": task_id}
129+
130+
def get_task(self, *, task_id: str) -> Dict[str, Any]:
131+
if task_id not in self._tasks:
132+
return {}
133+
return {self._tasks[task_id]}
134+
118135
def get_job(
119136
self, *, collection: str, job: str, version: str
120137
) -> Optional[Dict[str, Any]]:

tests/instance_launcher.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ def launch(
4747
running_workflow_step_id=running_workflow_step_id
4848
)
4949
assert "running_workflow_step" in response
50-
# Now simulate the creation of an Instance record
50+
# Now simulate the creation of a Task and Instance record
5151
response = self._api_adapter.create_instance(
5252
running_workflow_step_id=running_workflow_step_id
5353
)
54-
instance_id = response["instance_id"]
54+
instance_id = response["id"]
55+
response = self._api_adapter.create_task(instance_id=instance_id)
56+
task_id = response["id"]
5557

5658
# Just run the Python module that matched the 'job' in the step specification.
5759
# Don't care about 'version' or 'collection'.
@@ -70,14 +72,16 @@ def launch(
7072
pod_message.timestamp = f"{datetime.now(timezone.utc).isoformat()}Z"
7173
pod_message.phase = "Completed"
7274
pod_message.instance = instance_id
75+
pod_message.task = task_id
7376
pod_message.has_exit_code = True
7477
pod_message.exit_code = 0
7578
self._msg_dispatcher.send(pod_message)
7679

7780
return LaunchResult(
81+
# The errors returned here are the launch errors, not the Job's errors.
7882
error=0,
7983
error_msg=None,
8084
instance_id=instance_id,
81-
task_id="task-00000000-0000-0000-0000-000000000000",
85+
task_id=task_id,
8286
command=" ".join(job_cmd),
8387
)

tests/test_test_instance_launcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_get_nop_job(basic_launcher):
3838
workflow_id="workflow-00000000-0000-0000-0000-000000000000",
3939
running_workflow_step_id=rwfsid,
4040
workflow_definition={},
41-
step="step-1",
4241
step_specification={"job": "nop"},
4342
)
4443

workflow/workflow_abc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
181181
# [...],
182182
# }
183183

184+
@abstractmethod
185+
def create_task(self, instance_id: str) -> Dict[str, Any]:
186+
"""Create a Task Record (for amn Instance)"""
187+
# Should return:
188+
# {
189+
# "id": "task-00000000-0000-0000-0000-000000000001",
190+
# }
191+
192+
@abstractmethod
193+
def get_task(self, *, task_id: str) -> Dict[str, Any]:
194+
"""Get a Task Record"""
195+
# Should return:
196+
# {
197+
# "done": True,
198+
# "exit_code": 0,
199+
# [...],
200+
# }
201+
184202
@abstractmethod
185203
def get_job(
186204
self,

0 commit comments

Comments
 (0)