Skip to content

Commit 9f725a2

Browse files
Merge pull request #31 from InformaticsMatters/sc-3475
Now handles errors from realising outputs
2 parents 6c0e034 + cfc0115 commit 9f725a2

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

tests/wapi_adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import os
19+
from http import HTTPStatus
1920
from multiprocessing import Lock
2021
from pickle import Pickler, Unpickler
2122
from typing import Any
@@ -385,4 +386,4 @@ def realise_outputs(
385386
) -> tuple[dict[str, Any], int]:
386387
del running_workflow_step_id
387388
del outputs
388-
return {}, 0
389+
return {}, HTTPStatus.OK

workflow/workflow_engine.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import logging
2626
import sys
27+
from http import HTTPStatus
2728
from typing import Any, Dict, Optional
2829

2930
from decoder.decoder import TextEncoding, decode
@@ -259,26 +260,40 @@ def _handle_pod_message(self, msg: PodMessage) -> None:
259260
# Project directory, while also marking the Step as DONE (successfully).
260261
# We pass the outputs to the DM via a call to the API adapter's realise_outputs().
261262
# In return it copies (links) these files to the Project directory.
262-
#
263-
# We then inspect the Workflow to determine the next step.
264-
265263
wfid = rwf_response["workflow"]["id"]
266264
assert wfid
267265
wf_response, _ = self._wapi_adapter.get_workflow(workflow_id=wfid)
268266
_LOGGER.debug("API.get_workflow(%s) returned: -\n%s", wfid, str(wf_response))
269267

268+
error_num: int | None = None
269+
error_msg: str | None = None
270270
if output_values := get_workflow_output_values_for_step(wf_response, step_name):
271271
# Got some output values
272272
# Inform the DM so it can link them to the Project directory
273-
self._wapi_adapter.realise_outputs(
273+
response, status_code = self._wapi_adapter.realise_outputs(
274274
running_workflow_step_id=r_wfsid,
275275
outputs=output_values,
276276
)
277+
if status_code != HTTPStatus.OK:
278+
error_num = status_code
279+
error_msg = (
280+
response["error"]
281+
if "error" in response
282+
else "Undisclosed error when realising outputs"
283+
)
277284

278-
# Now we can mark this step as DONE...
285+
if error_num is not None:
286+
# The job was successful but linking outputs (back to the Project directory)
287+
# appears to have failed.
288+
self._set_step_error(step_name, r_wfid, r_wfsid, error_num, error_msg)
289+
return
290+
291+
# We then inspect the Workflow to determine the next step.
279292
self._wapi_adapter.set_running_workflow_step_done(
280293
running_workflow_step_id=r_wfsid,
281-
success=True,
294+
success=error_num is None,
295+
error_num=error_num,
296+
error_msg=error_msg,
282297
)
283298

284299
# We have the step from the Instance that's just finished,

0 commit comments

Comments
 (0)