next and Routers
REAL
next says where control goes when a step finishes. It has four
forms. The server tries them in this order when it parses the YAML
(NextSpec, orchestrate-core/src/playbook.rs, v3.161.2):
| # | Form | Example | Taken on the server |
|---|---|---|---|
| 1 | one step name | next: report | always |
| 2 | a list of names | next: [a, b] | all of them, in parallel |
| 3 | a list of targets {step, when?, args?} | next: [{step: a, when: …}, {step: b}] | by mode, exclusive by default |
| 4 | a router {spec: {mode}, arcs: [{step, when?, set?}]} | see below | by mode, exclusive by default |
All four in one playbook (examples/ch06/next-forms, a distributed
example that CI validates against the schema):
# Chapter 6.1: the four forms of `next`, on a server. Each form is one step.
apiVersion: noetl.io/v2
kind: Playbook
metadata:
name: next_forms
workload:
tier: gold
workflow:
- step: start
tool: { kind: noop }
next: by_name # 1. one step name: always taken
- step: by_name
tool: { kind: noop }
next: [fan_a, fan_b] # 2. a list of names: ALL taken (fan-out)
- step: fan_a
tool: { kind: noop }
next: # 3. a list of {step, when, args}: exclusive by default
- step: gold_path
when: "{{ workload.tier == 'gold' }}"
args: { reason: gold }
- step: other_path
- step: fan_b
tool: { kind: noop }
next: # 4. a router: spec.mode + arcs
spec: { mode: inclusive } # inclusive = every matching arc
arcs:
- step: audit
when: "{{ workload.tier in ['gold', 'silver'] }}"
- step: notify
set: { ctx.channel: email } # arc-level set: mutations for the target
- step: gold_path
tool: { kind: noop }
- step: other_path
tool: { kind: noop }
- step: audit
tool: { kind: noop }
- step: notify
tool: { kind: noop }
Exclusive and inclusive
Forms 3 and 4 decide which targets to take by mode
(evaluator.rs, v3.161.2):
exclusive(the default): take the first target, in the order written, whosewhenis true or absent. Later targets are not evaluated at all; they are recorded as skipped.inclusive: take every target whosewhenis true or absent. All are dispatched in the same pass, so they run in parallel.
A router reads its mode from next.spec.mode. A list of targets reads
it from the step's spec.next_mode. If neither is set, the mode is
exclusive. A misspelt mode value also means exclusive: any string
other than inclusive does.
"next: [{step: a}, {step: b}] runs a and b." It runs only a.
A list of targets is exclusive by default, and a target without
when always matches, so the first one wins and b is skipped. To
run both, write a list of names (next: [a, b]), or set
spec.next_mode: inclusive on the step, or use a router with
mode: inclusive.
Passing values along an arc
- A target in form 3 may carry
args, a map merged as-is into the target step's dispatch context. It is not rendered. - An arc in form 4 may carry
set, a map whose values are rendered against the current context and written with the samectx./iter./step.prefix-stripping as step-levelset:(4.2). It affects the context of the step it dispatches. Unlike a step's ownset:, it is not written to the event log as actx.updatedevent.
Routers do not take args, and the grammar's own comment says arc
args: is not supported. Use set.
On the local runtime
The local runtime (CLI v6.4.1) implements forms 3 and 4 the way the server does, except that "in parallel" becomes "one after another" in one process. CI checks both:
examples/ch06/next-targets: a list of targets runs only the first, soexecuted_stepsis["start","a"];examples/ch06/next-router-inclusive: an inclusive router runs both, soexecuted_stepsis["start","a","b"].
It does not implement forms 1 and 2:
# Chapter 6.1 (local, CLI 6.4.1): `next: <name>` and `next: [names]` are IGNORED locally; the run stops after `start` and still ends ok.
apiVersion: noetl.io/v2
kind: Playbook
metadata:
name: next_names_local
workflow:
- step: start
tool:
kind: rhai
code: |
"start"
next: [a, b]
- step: a
tool:
kind: rhai
code: |
"a"
- step: b
tool:
kind: rhai
code: |
"b"
{
"executed_steps": [
"start"
],
"final_result": "start",
"playbook_name": "next_names_local",
"status": "ok",
"step_results": {
"start": "start"
}
}
```admonish warning title="Locally, next: b and next: [a, b] do nothing"
At CLI v6.4.1, a next that is a bare name or a list of bare names
is ignored. The run stops after the step, with status ok and no
warning. For a playbook that must run locally too, write targets
(next: [{step: b}]) or a router.
## Check your understanding
<div class="quiz-placeholder" data-quiz-name=""ch06-01"" data-quiz-questions="{"questions":[{"context":"A list of TARGETS is exclusive by default, and a target without `when` always\nmatches, so the first wins and `b` is skipped. `next: [a, b]` (a list of\nNAMES) would run both.\n","id":"120d7a7d-513e-4c63-8989-9105531e3686","type":"MultipleChoice","answer":{"answer":"Only `a`."},"prompt":{"distractors":["`a` and `b`, in parallel.","`a`, then `b`.","Neither: targets need `when`."],"prompt":"On a server, which steps run after `next: [{step: a}, {step: b}]`?"}},{"context":"`NextMode` defaults to Exclusive, and any string other than `inclusive`\n(including a typo) parses as exclusive (orchestrate-core `evaluator.rs`).\n","id":"352b820e-b4bd-4d60-ac18-948a02cf9026","type":"MultipleChoice","answer":{"answer":"exclusive, unless the step's `spec.next_mode` says otherwise"},"prompt":{"distractors":["inclusive","parallel","It is a validation error."],"prompt":"A router omits `spec.mode`. Which mode applies?"}},{"context":"Locally only target lists and routers are implemented. CI asserts this\n(`examples/ch06/next-names-ignored-local`).\n","id":"2d031a66-6c9d-442e-8e8d-8c0c2befe8ef","type":"MultipleChoice","answer":{"answer":"Nothing: the bare-name forms are ignored locally and the run ends `ok`."},"prompt":{"distractors":["`a` and `b`.","`a` only.","The run fails to parse."],"prompt":"On the local runtime (CLI v6.4.1), a step has `next: [a, b]`. What runs after it?"}}]}" data-quiz-cache-answers="true"></div>
<script type="text/javascript" src="quiz/quiz-embed.iife.js"></script><link rel="stylesheet" type="text/css" href="quiz/style.css">