Skip to content

Commit 94fd202

Browse files
author
Alan Christie
committed
docs: Doc tweak
1 parent bea2cdb commit 94fd202

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

workflow/workflow_engine.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class StepPreparationResponse:
6565
variables: dict[str, Any] | None = None
6666
iteration_variable: str | None = None
6767
iteration_values: list[str] | None = None
68+
error_num: int = 0
6869
error_msg: str | None = None
6970

7071

@@ -306,12 +307,20 @@ def _handle_pod_message(self, msg: PodMessage) -> None:
306307
sp_resp = self._prepare_step(
307308
wf=wf_response, step_definition=next_step, rwf=rwf_response
308309
)
309-
if sp_resp.iterations == 0 or sp_resp.error_msg:
310+
if sp_resp.iterations == 0:
310311
# Cannot prepare variables for this step,
311-
# we have to leave.
312+
# it might be a combiner step and some prior steps may still
313+
# be running ... or something's gone wrong.
314+
if sp_resp.error_num:
315+
self._wapi_adapter.set_running_workflow_done(
316+
running_workflow_id=r_wfid,
317+
success=False,
318+
error_num=sp_resp.error_num,
319+
error_msg=sp_resp.error_msg,
320+
)
312321
return
313-
assert sp_resp.variables is not None
314322

323+
assert sp_resp.variables is not None
315324
self._launch(
316325
rwf=rwf_response,
317326
step_definition=next_step,
@@ -359,17 +368,19 @@ def _get_step_job(self, *, step: dict[str, Any]) -> dict[str, Any]:
359368
def _prepare_step(
360369
self,
361370
*,
362-
wf: dict[str, Any],
363371
step_definition: dict[str, Any],
372+
wf: dict[str, Any],
364373
rwf: dict[str, Any],
365374
) -> StepPreparationResponse:
366375
"""Attempts to prepare a map of step variables. If variables cannot be
367-
presented to the step we return an object with 'iterations' set to zero."""
376+
presented to the step we return an object with 'iterations' set to zero.
377+
If there's a problem that means we should be able to proceed but cannot,
378+
we set 'error_num' and 'error_msg'."""
368379

369380
step_name: str = step_definition["name"]
370381
rwf_id: str = rwf["id"]
371382

372-
# Before we move on, are we combiner?
383+
# Before we move on, are we a combiner?
373384
#
374385
# We are if a variable in our step's plumbing refers to an input of ours
375386
# that is of type 'files'. If we are a combiner then we use the name of the
@@ -397,17 +408,24 @@ def _prepare_step(
397408
break
398409
if step_name_being_combined:
399410
break
400-
if step_name_being_combined:
411+
412+
if step_is_combiner:
413+
assert step_name_being_combined
414+
assert combiner_input_variable
415+
416+
# Are all the step instances we're combining done?
417+
401418
response, _ = self._wapi_adapter.get_status_of_all_step_instances_by_name(
402419
name=step_name_being_combined,
403420
running_workflow_id=rwf_id,
404421
)
405-
# Assume succes...
406422
assert "count" in response
407423
num_step_recplicas_being_combined = response["count"]
408424
assert num_step_recplicas_being_combined > 0
409425
assert "status" in response
410426

427+
# Assume they're all done
428+
# and undo our assumption if not...
411429
all_step_instances_done: bool = True
412430
all_step_instances_successful: bool = True
413431
for status in response["status"]:
@@ -418,7 +436,7 @@ def _prepare_step(
418436
all_step_instances_successful = False
419437
break
420438
if not all_step_instances_done:
421-
# Can't move on - but other steps need to finish.
439+
# Can't move on - other steps need to finish.
422440
_LOGGER.debug(
423441
"Assessing start of combiner step (%s)"
424442
" but not all steps (%s) to be combined are done",
@@ -428,15 +446,16 @@ def _prepare_step(
428446
return StepPreparationResponse(iterations=0)
429447
elif not all_step_instances_successful:
430448
# Can't move on - all prior steps are done,
431-
# but at least one was in error.
432-
_LOGGER.debug(
449+
# but at least one was not successful.
450+
_LOGGER.warning(
433451
"Assessing start of combiner step (%s)"
434452
" but at least one step (%s) to be combined failed",
435453
step_name,
436454
step_name_being_combined,
437455
)
438456
return StepPreparationResponse(
439457
iterations=0,
458+
error_num=1,
440459
error_msg=f"Prior instance of step '{step_name_being_combined}' has failed",
441460
)
442461

@@ -448,11 +467,11 @@ def _prepare_step(
448467
variables: dict[str, Any] = step_definition["specification"].get(
449468
"variables", {}
450469
)
451-
452-
# All the running workflow variables
470+
# ...and the running workflow variables
453471
rwf_variables: dict[str, Any] = rwf.get("variables", {})
454472

455-
# Process the step's plumbing realting to workflow variables.
473+
# Process the step's "plumbing" relating to workflow variables.
474+
#
456475
# This will be a list of Connectors of "in" and "out" variable names.
457476
# "in" variables are worklfow variables, and "out" variables
458477
# are expected Job variables. We use this to add variables
@@ -463,13 +482,12 @@ def _prepare_step(
463482
assert connector.in_ in rwf_variables
464483
variables[connector.out] = rwf_variables[connector.in_]
465484

466-
# Now we apply variables from the "plumbing" block
467-
# related to values used in prior steps. The decoder gives
468-
# us a map indexed by prior step name that's a list of "in" "out"
469-
# tuples as above.
485+
# Now process variables (from the "plumbing" block)
486+
# that relate to values used in prior steps.
470487
#
471-
# If this is a combiner step remember that we need to inspect
472-
# variables from all the prior steps.
488+
# The decoder gives us a map indexed by prior step name that's a list of
489+
# "in" "out" connectors as above. If this is a combiner step remember
490+
# that we need to inspect variables from all the prior steps.
473491
prior_step_plumbing: dict[str, list[Connector]] = get_step_prior_step_plumbing(
474492
step_definition=step_definition
475493
)
@@ -486,6 +504,8 @@ def _prepare_step(
486504
)
487505
)
488506
# Copy "in" value to "out"...
507+
# accumulating thiose for the 'combining' variable,
508+
# which will be set as a list when we're done.
489509
for connector in connections:
490510
assert connector.in_ in prior_step["variables"]
491511
if connector.out == combiner_input_variable:
@@ -508,16 +528,17 @@ def _prepare_step(
508528
assert connector.in_ in prior_step["variables"]
509529
variables[connector.out] = prior_step["variables"][connector.in_]
510530

511-
# Now ... can the command be compiled!?
531+
# All variables are set ...
532+
# is this enough to satisfy the setp's Job command?
533+
512534
job: dict[str, Any] = self._get_step_job(step=step_definition)
513535
message, success = job_defintion_decoder.decode(
514536
job["command"], variables, "command", TextEncoding.JINJA2_3_0
515537
)
516538
if not success:
517-
msg = f"Failed command validation error_msg={message}"
539+
msg = f"Failed command validation for step {step_name} error_msg={message}"
518540
_LOGGER.warning(msg)
519-
self._set_step_error(step_name, rwf_id, None, 1, msg)
520-
return StepPreparationResponse(iterations=0)
541+
return StepPreparationResponse(iterations=0, error_num=2, error_msg=msg)
521542

522543
# Do we replicate this step (run it more than once)?
523544
#

0 commit comments

Comments
 (0)