chained-runs

TriggerDagOperator, dependencies between DAGs.

Generated by make records from the decisions whose topic (or also) is this one; edit the decisions, not this page.

Current

Waiting for runs

  • RunOf waits for or triggers from another DAG’s run (D353): RunOf selects another DAG’s run or task; lagged waits use this run’s planned_for minus lag and choose the newest matching run by triggered_at. The master-ended node yields a run ID or TimedOut; failed, cancelled or skipped targets yield routed Failed, otherwise failing the node and run. No-code triggers start runs only for successful completions while live, without catching up paused periods. Function sensors and triggers receive RunResult[T] on watcher slots for all terminal states; sensors may return NOT_YET, and failed calls retry the same handed run, with trigger retry limits or manual skip available.

Building it

  • Build the trigger operator and backfill in two parts (D357): M4.12a builds TriggerDagOperator. M4.12b builds backfill.

TriggerDagOperator

  • TriggerDagOperator gives the target run’s ID (D358): The operator’s value is the target run’s ID, whether or not wait=True. The target’s output can be read with a RunOf sensor or the API.

  • A failed target gives a routable Failed outcome (D359): A failed, cancelled or skipped target gives Failed, including its state. The DAG can route it with .on(Failed); otherwise the operator task fails.

  • max_wait times out without cancelling the target run (D360): When the operator’s max_wait expires it yields TimedOut. The target run continues.

  • An operator retry starts a new run only after failure (D361): A retry starts a new target run only after the previous run failed. The run’s ID is recorded on the task’s attempt first and the run created by that ID, so a master stopped in between creates it once, never two.

  • A triggered run accepts an optional planned_for (D362): planned_for accepts a datetime or a reference and defaults to the parent’s planned time. Airflow’s logical_date maps to it.

  • Tasks start runs with TriggerDagOperator (D365): Tasks start runs with TriggerDagOperator. The task routes of schedr.api remain limited to events.

  • A missing or conflicting target fails the operator, with its retries (D379): A TriggerDagOperator whose target DAG is missing or in an ID conflict when it runs fails with the reason, and the task’s retries apply (the target’s root may not be parsed yet). Invalid params still fail without retries.

  • A waiting TriggerDagOperator doesn’t count towards the DAG’s limits (D380): A TriggerDagOperator holds no worker and no slot, and its attempt doesn’t count towards max_active_tasks, max_active or max_active_per_run, as wait_for nodes don’t. Replaces the earlier text that it counts as a running task.

  • A TriggerDagOperator starts only a DAG with trigger=Chained() (D398): A DAG’s runs come one way: its own trigger, or other DAGs’ TriggerDagOperators, which start only a DAG with trigger=Chained() (any DAG) or Chained(by=[...]) (those named; by=[] is an error). Any other target fails the task when it runs (chained_target_refused, not retried); a paused one too, with retries. schedr dags check fails the operator’s file when its target in the root refuses it; the master’s parse doesn’t. trigger=None means manual runs only: nothing to pause, no Pause in the UI, pause and unpause refused (decisions 457 and 459). Manual runs stay allowed on every DAG, a fallback and for testing. schedr dags test unpauses the Chained DAGs of the path tested.

  • Cycles between DAGs are allowed; only a cycle inside a DAG is refused (D399): DAGs may start each other in a cycle, through TriggerDagOperators, RunOf triggers or events: no check follows the chain of parent runs. Inside a DAG a cycle is refused when its file loads: its tasks depending on each other, a TriggerDagOperator naming its own DAG, Chained(by=...) naming it. A run started by a RunOf trigger records the run that started it as its parent, linked both ways in the UI as a chained run is.

  • Of the operators, only a TriggerDagOperator is mapped (D406): .partial() and .expand() are on @task functions and on TriggerDagOperator only: CommandOperator, ScriptOperator and EmptyOperator can’t be mapped. The official ways to run a command or script per element: a mapped @task starting the process, or a mapped TriggerDagOperator whose target DAG runs the operator on its params (a for loop in the DAG file for a list known when it loads). Wait steps aren’t mapped either (Q21, deferred to M6).

  • A mapped TriggerDagOperator starts a run per element (D407): TriggerDagOperator.partial("fan", dag="region", ...).expand(params=regions) (or planned_for=, or .expand_kwargs([{"params": ..., "planned_for": ...}])), the list a literal or an upstream output, starts one chained run per element: each instance its own attempt and run, its value the run’s ID, Failed or TimedOut per element; the task’s output is the list of them. dag, wait, max_wait and the options stay fixed; an argument is fixed or mapped, never both.

Tests

  • In tests a TriggerDagOperator starts a real run of a target in the tested path (D378): In schedr dags test and run_dag, a TriggerDagOperator starts the target’s run on the local master when the target is in the path given (a DAG root); a target outside it fails the task with a hint that its DAG file must be in the path tested. There is no stub.

Replaced

  • D381 (superseded by D407): Operators are mapped in a later step, TriggerDagOperator with them

Where in code

  • crates/schedr-agent/src/agent.rs (D353)

  • crates/schedr-api/src/routes.rs (D353)

  • crates/schedr-api/src/views.rs (D353)

  • crates/schedr-db/src/attempts.rs::ACTIVE_ATTEMPTS (D380)

  • crates/schedr-db/src/attempts.rs::start_chained_attempt (D361)

  • crates/schedr-db/src/run_of.rs::runs_of (D353)

  • crates/schedr-master/src/dispatch/chained.rs::TARGET_MISSING (D378)

  • crates/schedr-master/src/dispatch/chained.rs::chained_step (D358, D360)

  • crates/schedr-master/src/dispatch/chained.rs::create_chained (D361, D362, D379)

  • crates/schedr-master/src/dispatch/chained.rs::element (D407)

  • crates/schedr-master/src/dispatch/chained.rs::run_ended (D359)

  • crates/schedr-master/src/progress.rs::NOT_RETRIED_ERRORS (D379)

  • crates/schedr-master/src/scheduler.rs::NotChained (D398)

  • crates/schedr-master/src/scheduler.rs::event_run (D399)

  • crates/schedr-master/src/scheduler.rs::trigger_chained (D361)

  • crates/schedr-master/src/validate.rs::chained_trigger_problems (D399)

  • crates/schedr-master/src/validate.rs::expand_problems (D406)

  • crates/schedr-master/src/validate.rs::target_problems (D379, D398)

  • crates/schedr-master/src/validate.rs::trigger_dag_expand_problems (D407)

  • crates/schedr-model/src/trigger.rs::chained_from (D398)

  • crates/schedr/src/local.rs::unpause_chained (D398)

  • python/schedr/chained.py::Chained (D398)

  • python/schedr/chained.py::PartialTriggerDag (D407)

  • python/schedr/chained.py::TriggerDagOperator (D358, D362, D365)

  • python/schedr/chained.py::partial (D406)

  • python/schedr/run_of.py::RunOf (D353)

  • python/tests/integration/test_testing.py::test_a_trigger_dag_runs_its_target_from_the_path_tested (D378)

Open

None.

Details and edge cases, with the reasons; read them before changing this:

  • JOURNAL.md: D378, D379, D380, D381, D398, D399, D406, D407

  • archive/PROJECT.md: Dependencies between DAGs, Sensors and triggers