Configuring app runs individually¶
Reference
Learn more about the AppRunConfig class in the technical reference.
By default, the run configuration and instance of an app step are set once, on the
app decorator. Every run of that step then uses the same values. When fanning
out with the foreach decorator, this is not always what you want: the
workflow often already knows something about each scenario that should influence how
it runs.
For this, an AppRunConfig can carry its own RunConfiguration
and instance_id, in addition to the input and options.
Choosing the execution class per run¶
The following example gives large scenarios a bigger execution class:
import nextmv
from nextpipe import AppRunConfig, app, foreach, needs, step
@foreach()
@step
def create_scenarios(data: dict):
"""Create scenarios, sizing the run to the scenario at hand."""
return [
AppRunConfig(
name=f"scenario-{scenario['id']}",
input=scenario,
run_configuration=nextmv.RunConfiguration(
execution_class="8c16gb12h" if scenario["large"] else "4c8gb12h",
),
)
for scenario in split(data)
]
@needs(predecessors=[create_scenarios])
@app(app_id="solver-app")
@step
def solve():
"""Run external solver for each scenario."""
pass
Choosing the instance per run¶
In the same way, instance_id sends a run to a specific instance, e.g., one tuned for
large scenarios. Scenarios that leave it unset run on the instance given to the
decorator:
How the values are combined¶
Both fields are optional. If set, they replace the corresponding argument of the
app decorator for that run, rather than merging with it. For
run_configuration this means the whole configuration is replaced — no individual
fields are inherited from the decorator. If a field is left unset on the
AppRunConfig, the value from the decorator is used unchanged.
Note
This differs from options, which are merged, with the ones on the AppRunConfig
taking precedence over the ones on the decorator.