Skip to content

Commit cf6cfbe

Browse files
author
Alan Christie
committed
fix: Engine now handles lack of job better
1 parent 079736c commit cf6cfbe

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

workflow/workflow_engine.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ def _get_step_job(self, *, step: dict[str, Any]) -> dict[str, Any]:
417417
# the keys "collection", "job", and "version". Here we assume that
418418
# the workflow definition has passed the RUN-level validation
419419
# which means we can get these values.
420+
#
421+
# The validator should have verified the Job exists, but it might not
422+
# when we need it - so this method might return '{}'.
420423
assert "specification" in step
421424
step_spec: dict[str, Any] = step["specification"]
422425
job_collection: str = step_spec["collection"]
@@ -464,6 +467,12 @@ def _prepare_step(
464467
# whose origin is of type 'files'.
465468

466469
our_job_definition: dict[str, Any] = self._get_step_job(step=step_definition)
470+
if not our_job_definition:
471+
return StepPreparationResponse(
472+
replicas=0,
473+
error_num=1,
474+
error_msg=f"The Job for step '{step_name}' is not present",
475+
)
467476
our_inputs: dict[str, Any] = job_definition_decoder.get_inputs(
468477
our_job_definition
469478
)
@@ -540,7 +549,7 @@ def _prepare_step(
540549
)
541550
return StepPreparationResponse(
542551
replicas=0,
543-
error_num=1,
552+
error_num=2,
544553
error_msg=f"Prior instance of step '{step_name_being_combined}' has failed",
545554
)
546555

@@ -661,14 +670,16 @@ def _prepare_step(
661670
# we give the step's Job command and our prime variables
662671
# to the Job decoder - it wil tell us if an important
663672
# variable is missing....
664-
job: dict[str, Any] = self._get_step_job(step=step_definition)
665673
message, success = job_definition_decoder.decode(
666-
job["command"], prime_variables, "command", TextEncoding.JINJA2_3_0
674+
our_job_definition["command"],
675+
prime_variables,
676+
"command",
677+
TextEncoding.JINJA2_3_0,
667678
)
668679
if not success:
669680
msg = f"Failed command validation for step {step_name} error_msg={message}"
670681
_LOGGER.warning(msg)
671-
return StepPreparationResponse(replicas=0, error_num=2, error_msg=msg)
682+
return StepPreparationResponse(replicas=0, error_num=3, error_msg=msg)
672683

673684
# Do we replicate this step (run it more than once in parallel)?
674685
#
@@ -699,6 +710,12 @@ def _prepare_step(
699710
wf_step: dict[str, Any] = get_step(wf, p_step_name)
700711
assert wf_step
701712
job_definition: dict[str, Any] = self._get_step_job(step=wf_step)
713+
if not job_definition:
714+
return StepPreparationResponse(
715+
replicas=0,
716+
error_num=4,
717+
error_msg=f"The Job for step '{p_step_name}' is not present",
718+
)
702719
jd_outputs: dict[str, Any] = job_definition_decoder.get_outputs(
703720
job_definition
704721
)

0 commit comments

Comments
 (0)