schedr.chained¶
TriggerDagOperator starts a run of another DAG; Chained lets it (decisions 357-365, 398).
The master carries it out, with no process and no worker slot: it creates a chained run of
the target, linked to this run, and with wait=True (the default) waits for it to end.
- class schedr.chained.Chained(by=None)¶
Bases:
TriggerDag(trigger=Chained()): only other DAGs’TriggerDagOperatortasks start its runs.A DAG’s runs come one way (decision 398): its own trigger, or other DAGs’ TriggerDagOperators, which start only a
ChainedDAG. People can still start it by hand, as any DAG. Paused, it refuses them: the operator fails, and its retries apply.- Parameters:
by (Sequence[str] | None)
- by¶
The DAG IDs whose operators may start it; any DAG’s if not given. Not empty.
- Type:
collections.abc.Sequence[str] | None
- to_model()¶
The trigger in DAG JSON.
- Returns:
The DAGs that may start it.
- Return type:
- class schedr.chained.TriggerDagOperator(task_id, *, dag, params=None, wait=True, planned_for=None, max_wait=None, retries=None, retry_delay=None, run_if=None)¶
Bases:
OperatorStarts a run of another DAG:
TriggerDagOperator("load", dag="dwh_load").The target is a DAG with
trigger=Chained(), orChained(by=[...])naming this DAG (decision 398); any other fails the task, not retried, and a paused one fails it, retried. The run ischainedto this one (itstriggered_by), planned for this run’splanned_forunlessplanned_forsays otherwise, queued with a manual run’s priority. The task’s value is the run’s ID, astr.With
wait=True(the default) the task ends when the run has: its value when the run succeeded;Failed(its state and ID) when it failed, was cancelled or skipped, which the DAG routes with.on(Failed)or the task fails;TimedOutaftermax_wait, the run left going. Cancelling this run cancels a run it waits for. A retry starts a new run only after the previous one failed. Withwait=Falseit ends once the run is created.It holds no worker and doesn’t count towards the DAG’s limits (decision 380). A target that is missing, in an ID conflict or paused fails the task, with its retries (decision 379); parameters the target refuses, or a target that isn’t
Chainedfor this DAG, fail it without. DAGs may start each other in a cycle (decision 399). Read the target run’s output with@sensor(wait_for=RunOf(...))or the API.- Parameters:
task_id (str) – The task’s ID.
dag (str) – The target DAG’s ID.
params (Mapping[str, object] | None) – The run’s parameters, over the target’s defaults: literals, upstream outputs or
dag_ctxreferences, checked against the target’s schema when the task runs.wait (bool) – Whether the task waits for the run to end.
planned_for (datetime | object | None) – The run’s
planned_for: an awaredatetimeor a reference (dag_ctx.run.planned_for); this run’s if not given. Airflow’slogical_date.max_wait (timedelta | None) – How long it waits (with
wait=True); the master’s[sensors] default_max_waitif not given.retries (int | None) – How many times a failed task is tried again.
retry_delay (timedelta | None) – How long it waits before trying again.
run_if (RunIf | None) – When it runs, from its upstream edges.
- Raises:
RuntimeError – Outside
with Dag(...).TypeError – For a target that isn’t a DAG ID, parameters that aren’t a dict with string keys, or a
max_waitwithwait=False.
- classmethod partial(task_id, *, dag, params=None, wait=True, planned_for=None, max_wait=None, retries=None, retry_delay=None, run_if=None)¶
Fixes the settings of a mapped one:
.partial("fan", dag="region").expand(params=...).Mapped (decision 407), it starts one run per element of what
.expand()or.expand_kwargs()maps over:paramsorplanned_for, the others fixed here.- Parameters:
task_id (str) – The task’s ID.
dag (str) – The target DAG’s ID.
params (Mapping[str, object] | None) – The runs’ parameters, if not mapped.
wait (bool) – Whether each instance waits for its run to end.
planned_for (datetime | object | None) – The runs’
planned_for, if not mapped.max_wait (timedelta | None) – How long each instance waits.
retries (int | None) – How many times a failed instance is tried again.
retry_delay (timedelta | None) – How long it waits before trying again.
run_if (RunIf | None) – When it runs, from its upstream edges.
- Returns:
The operator with them fixed, to
.expand(...).- Return type:
- property output: str¶
a reference, read by type checkers as its value.
With
wait=True, only when the run succeeded (.on(str)): a task taking it is skipped onFailedorTimedOutunless something takes those.- Type:
The started run’s ID
- on(kind: type[U], /) U¶
- on(kind: type[U], other: type[V], /) U | V
- on(kind: None, /) Done
- on(kind: DefaultOutcome, /) str
Depends on it only for these outcomes:
.on(str),.on(Failed),.on(TimedOut).- Parameters:
*kinds (object) –
str(the run succeeded),Failed,TimedOut, orNone(any).- Returns:
The narrowed reference (see
Output.on).- Return type:
object
- class schedr.chained.PartialTriggerDag(task_id, fixed)¶
Bases:
objectA
TriggerDagOperatorwith its settings fixed, to map (TriggerDagOperator.partial).- Parameters:
task_id (str)
fixed (_Fixed)
- expand(**mapped)¶
One run per element:
.expand(params=regions),.expand(planned_for=days).Each list is a literal or an upstream output; several are combined as their cartesian product, the first varying slowest.
- Parameters:
**mapped (object) –
params(a list of dicts),planned_for(a list of aware datetimes), or both.- Returns:
The mapped task; its output is the list of the runs’ IDs.
- Raises:
RuntimeError – Outside
with Dag(...).TypeError – For nothing mapped, another argument, or one also fixed.
- Return type:
- expand_kwargs(values)¶
One run per dict of
values:[{"params": {...}, "planned_for": ...}, ...].- Parameters:
values (object) – A list of dicts naming
params,planned_foror both (a literal, or an upstream output that is one).- Returns:
The mapped task; its output is the list of the runs’ IDs.
- Raises:
RuntimeError – Outside
with Dag(...).TypeError – For an element written here that isn’t a dict, or names another argument or one also fixed.
- Return type:
- class schedr.chained.MappedTriggerDagOperator(task_id, *, dag, params=None, wait=True, planned_for=None, max_wait=None, retries=None, retry_delay=None, run_if=None)¶
Bases:
TriggerDagOperatorA mapped
TriggerDagOperator(decision 407): one run per element.Each instance’s outcome is its own. Made by
TriggerDagOperator.partial(...).expand(...).- Parameters:
task_id (str)
dag (str)
params (Mapping[str, object] | None)
wait (bool)
planned_for (datetime | object | None)
max_wait (timedelta | None)
retries (int | None)
retry_delay (timedelta | None)
run_if (RunIf | None)
- property output: list[str | Failed | TimedOut]¶
a reference.
Its run’s ID; with
wait=True, itsFailedorTimedOutinstead when it ended so (each instance has its own outcome, so the whole list isn’t narrowed: filter it in a task). Withwait=Falseevery element is a run’s ID.- Type:
Each instance’s value, in the order of the elements