|
39 | 39 | )
|
40 | 40 |
|
41 | 41 | from .decoder import (
|
| 42 | + ReplicationDriver, |
| 43 | + ReplicationOrigin, |
42 | 44 | Translation,
|
43 | 45 | get_step_prior_step_variable_mapping,
|
| 46 | + get_step_replication_driver, |
44 | 47 | get_step_workflow_variable_mapping,
|
45 | 48 | )
|
46 | 49 |
|
@@ -340,8 +343,6 @@ def _validate_step_command(
|
340 | 343 | name=prior_step_name, running_workflow_id=running_workflow_id
|
341 | 344 | )
|
342 | 345 | # Copy "in" value to "out"...
|
343 |
| - print(v_map) |
344 |
| - print(prior_step["variables"]) |
345 | 346 | for tr in v_map:
|
346 | 347 | assert tr.in_ in prior_step["variables"]
|
347 | 348 | all_variables[tr.out] = prior_step["variables"][tr.in_]
|
@@ -378,34 +379,63 @@ def _launch(self, *, rwf: dict[str, Any], step: dict[str, Any]) -> None:
|
378 | 379 | return
|
379 | 380 |
|
380 | 381 | variables: dict[str, Any] = error_or_variables
|
381 |
| - num_replicas: int = 0 |
382 |
| - # Is this a replicating step? |
383 |
| - # The number of 'replicas' is zero if the step is only launched once |
384 |
| - # (i.e. there are no replicas). |
385 |
| - |
386 |
| - # replicator = get_step_replicator(step=step) |
387 |
| - # if replicator: |
388 |
| - # single_step_variables = [] |
389 |
| - # for replicating_param in variables[replicator]: |
390 |
| - # ssv = {**variables} |
391 |
| - # ssv[replicator] = replicating_param |
392 |
| - # single_step_variables.append(ssv) |
393 |
| - # else: |
394 |
| - # single_step_variables = [variables] |
395 |
| - |
396 |
| - assert num_replicas >= 0 |
397 |
| - step_replication_number: int = 1 if num_replicas else 0 |
398 |
| - for _ in range(1 + num_replicas): |
| 382 | + |
| 383 | + # A replication number, |
| 384 | + # use only for steps expected to replicate (even if just once) |
| 385 | + step_replication_number: int = 0 |
| 386 | + # Does this step have a replicating driver? |
| 387 | + r_driver: ReplicationDriver | None = get_step_replication_driver(step=step) |
| 388 | + replication_values: list[str] = [] |
| 389 | + if r_driver: |
| 390 | + if r_driver.origin == ReplicationOrigin.STEP_VARIABLE: |
| 391 | + # We need to get the variable values from a prior step |
| 392 | + # We need the prior steps running-workflow-step-id |
| 393 | + assert r_driver.source_step_name |
| 394 | + response, _ = self._wapi_adapter.get_running_workflow_step_by_name( |
| 395 | + name=r_driver.source_step_name, |
| 396 | + running_workflow_id=rwf_id, |
| 397 | + ) |
| 398 | + assert "id" in response |
| 399 | + o_rwfs_id: str = response["id"] |
| 400 | + response, _ = ( |
| 401 | + self._wapi_adapter.get_running_workflow_step_output_values_for_output( |
| 402 | + running_workflow_step_id=o_rwfs_id, |
| 403 | + output_variable=r_driver.source_variable, |
| 404 | + ) |
| 405 | + ) |
| 406 | + assert "output" in response |
| 407 | + replication_values = response["output"] |
| 408 | + else: |
| 409 | + assert False, "Unsupported origin" |
| 410 | + |
| 411 | + num_step_instances: int = max(1, len(replication_values)) |
| 412 | + for iteration in range(num_step_instances): |
| 413 | + |
| 414 | + # If we are replicating this step then we must replace the step's variable |
| 415 | + # with a value expected for this iteration. |
| 416 | + if r_driver: |
| 417 | + iter_variable: str = r_driver.variable |
| 418 | + iter_value: str = replication_values[iteration] |
| 419 | + _LOGGER.info( |
| 420 | + "Replicating step: %s iteration=%s variable=%s value=%s", |
| 421 | + step_name, |
| 422 | + iteration, |
| 423 | + iter_variable, |
| 424 | + iter_value, |
| 425 | + ) |
| 426 | + # Over-write the replicating variable |
| 427 | + # and set the replication numebr to a unique +ve non-zero value... |
| 428 | + variables[iter_variable] = iter_value |
| 429 | + step_replication_number = iteration + 1 |
399 | 430 |
|
400 | 431 | _LOGGER.info(
|
401 | 432 | "Launching step: %s RunningWorkflow=%s (name=%s)"
|
402 |
| - " variables=%s project=%s (step_replication_number=%s)", |
| 433 | + " variables=%s project=%s", |
403 | 434 | step_name,
|
404 | 435 | rwf_id,
|
405 | 436 | rwf["name"],
|
406 | 437 | variables,
|
407 | 438 | project_id,
|
408 |
| - step_replication_number, |
409 | 439 | )
|
410 | 440 |
|
411 | 441 | lp: LaunchParameters = LaunchParameters(
|
@@ -436,10 +466,6 @@ def _launch(self, *, rwf: dict[str, Any], step: dict[str, Any]) -> None:
|
436 | 466 | lr.command,
|
437 | 467 | )
|
438 | 468 |
|
439 |
| - # Do we need to increment the replication number? |
440 |
| - if num_replicas: |
441 |
| - step_replication_number += 1 |
442 |
| - |
443 | 469 | def _set_step_error(
|
444 | 470 | self,
|
445 | 471 | step_name: str,
|
|
0 commit comments