schedr.run_of¶
Waiting for a run of another DAG: RunOf and wait_for (decision 353).
- schedr.run_of.MAX_LAG = datetime.timedelta(days=3650)¶
10 years (the master’s
MAX_LAG_MS).- Type:
The longest
lag, either way
- class schedr.run_of.RunOf(dag, task=None, lag=None)¶
Bases:
TriggerWhich run of another DAG to wait for, or, as a DAG’s trigger, which runs start one of it.
RunOf("orders")is the next run ofordersto end;RunOf("orders", task="load", lag=timedelta(hours=6))is theloadof the run planned six hours before this one. AsDag("report", trigger=RunOf("orders", lag=timedelta(hours=6))), each run ofordersthat succeeds starts one ofreport, planned six hours after it (withoutlag, for the moment it is seen); only those ending whilereportis live count, none caught up.- Parameters:
dag (str)
task (str | None)
lag (timedelta | None)
- dag¶
The DAG’s ID.
- Type:
str
- task¶
Its task;
None: the whole run.- Type:
str | None
- lag¶
How long before this run’s
planned_forthat run was planned for;None: the next run to end after the step starts.- Type:
datetime.timedelta | None
- property lag_ms: int | None¶
The lag in milliseconds, as stored.
- to_model()¶
The trigger in DAG JSON.
- Returns:
Its model.
- Raises:
ValueError – For a negative lag: a run can’t be planned before the one starting it.
- Return type:
- class schedr.run_of.RunResult(run_id, dag_id, planned_for, state, ended_at=None, task_id=None, task_state=None, outcome=None, output=None)¶
Bases:
GenericThe run of another DAG an
@sensor(wait_for=RunOf(...))is called for (decision 353).Its function’s first parameter:
async def check(run: RunResult[Orders]) -> Report | NotYet. It is called once that run (or its task) has ended, whatever its state; returningNOT_YETwaits for a later matching run (withlag, a newer one for the same moment, as when it is run again), untilmax_wait.- Parameters:
run_id (str)
dag_id (str)
planned_for (datetime)
state (str)
ended_at (datetime | None)
task_id (str | None)
task_state (str | None)
outcome (str | None)
output (T | None)
- run_id¶
The run’s ID.
- Type:
str
- dag_id¶
Its DAG.
- Type:
str
- planned_for¶
Its
planned_for.- Type:
datetime.datetime
- state¶
How it ended:
success,failed,cancelled, …; stillrunningwhen only its task (RunOf(task=...)) is what was waited for.- Type:
str
- ended_at¶
When it ended, if it has.
- Type:
datetime.datetime | None
- task_id¶
With
RunOf(task=...), that task.- Type:
str | None
- task_state¶
Its state:
success,failed, …;Noneif the run ended without it.- Type:
str | None
- outcome¶
Its outcome (
SUCCESS, or an outcome class’s name), if it succeeded.- Type:
str | None
- output¶
Its output, as
T, if it succeeded (a mapped task’s, the list of its elements’), masked as the API masks it: secret fields and URL passwords****.- Type:
T | None
- schedr.run_of.run_parameter(fn, where, given=<class 'schedr.run_of.RunResult'>)¶
The name of a
wait_for=function’s first parameter, given the run or the event.- Parameters:
fn (Callable[..., object]) – An
@sensor(wait_for=...)’s or@trigger(wait_for=...)’s function.where (str) – Who it is, for messages.
given (type) – What it is given:
RunResultfor aRunOf,Eventfor anEventNamed(decision 354).
- Returns:
The parameter’s name.
- Raises:
TypeError – If it has none, or it isn’t annotated as what it is given.
- Return type:
str
- schedr.run_of.wait_for(run_of: RunOf, *, max_wait: timedelta | None = None, task_id: str | None = None) Waited[str]¶
- schedr.run_of.wait_for(run_of: EventNamed, *, max_wait: timedelta | None = None, task_id: str | None = None) Waited[Event[Json]]
A step the master ends when that run, or its task, has ended: no process, no slot.
Its value is that run’s ID:
build(wait_for(RunOf("orders")).on(str)). It endsFailedwhen the run or task didn’t succeed: route it with.on(Failed), or the step fails and its run too. Aftermax_waitwith no such run it endsTimedOut, as any wait step.Given an
EventNamed(decision 354), it waits for the first event of that name (and key) posted since its run was created, and its value is that event:Event[Json], read asship(wait_for(EventNamed("paid", key=dag_ctx.params.order)).on(Event)).- Parameters:
run_of (RunOf | EventNamed) – Which run, and which task of it; or which event.
max_wait (timedelta | None) – How long it waits; the master’s
[sensors] default_max_waitif not given.task_id (str | None) – Its ID;
wait_for_<task or DAG>, numbered from the second on, if not given.
- Returns:
The step’s output, read as its value,
FailedorTimedOut.- Raises:
TypeError – For what isn’t a
RunOfor anEventNamed.- Return type:
- schedr.run_of.call_limit_ms(timeout, where)¶
A
wait_for=function’stimeoutfor one call, in milliseconds (decision 353).- Returns:
The milliseconds.
- Raises:
TypeError – Unless it is a
timedeltaabove zero, in whole milliseconds.- Parameters:
timeout (timedelta)
where (str)
- Return type:
int