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: Trigger

Which 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 of orders to end; RunOf("orders", task="load", lag=timedelta(hours=6)) is the load of the run planned six hours before this one. As Dag("report", trigger=RunOf("orders", lag=timedelta(hours=6))), each run of orders that succeeds starts one of report, planned six hours after it (without lag, for the moment it is seen); only those ending while report is 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_for that 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:

RunOfTrigger

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: Generic

The 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; returning NOT_YET waits for a later matching run (with lag, a newer one for the same moment, as when it is run again), until max_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, …; still running when 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, …; None if 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: RunResult for a RunOf, Event for an EventNamed (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 ends Failed when the run or task didn’t succeed: route it with .on(Failed), or the step fails and its run too. After max_wait with no such run it ends TimedOut, 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 as ship(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_wait if 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, Failed or TimedOut.

Raises:

TypeError – For what isn’t a RunOf or an EventNamed.

Return type:

Waited[str] | Waited[Event[Json]]

schedr.run_of.call_limit_ms(timeout, where)

A wait_for= function’s timeout for one call, in milliseconds (decision 353).

Returns:

The milliseconds.

Raises:

TypeError – Unless it is a timedelta above zero, in whole milliseconds.

Parameters:
  • timeout (timedelta)

  • where (str)

Return type:

int