schedr.sensors

Wait steps: @sensor and @sensor.poke.

A wait step is a task that waits for one thing belonging to its run and ends, with a value or with the TimedOut outcome (waiting in vain is an expected problem, not a failure).

class schedr.sensors.NotYet(*values)

Bases: Enum

The type of NOT_YET: what @sensor.poke returns while it has nothing.

schedr.sensors.NOT_YET: Final = NotYet.NOT_YET

What a @sensor.poke function returns until it has its value (so None is a value); an @sensor(wait_for=...) returns it for a run that isn’t the one, to wait for a later one.

schedr.sensors.NOT_YET_OUTCOME: Final = 'NotYet'

The outcome an @sensor(wait_for=...)’s attempt ends with when it returned NOT_YET: the master then waits for a later matching run (its NOT_YET_OUTCOME).

class schedr.sensors.SensorOptions

Bases: TypedDict

@task’s options that a wait step has too (decision 323).

max_wait: timedelta | None

How long it waits before ending with TimedOut, from its first start, across retries; default: max_wait of StepDefaults, then [sensors] default_max_wait.

schedr.sensors.output_hint(annotation)

A wait step’s return annotation without NotYet: the type of its output.

Parameters:

annotation (object) – The annotation as written.

Returns:

Path for Path | NotYet; the annotation itself if NotYet isn’t in it.

Return type:

object

class schedr.sensors.SensorFunction(fn, task_id, options, every, wait_for=None, call_timeout_ms=None)

Bases: AsyncTaskFunction[P, R, A], Generic[P, R, A]

A function decorated with @sensor or @sensor.poke: a wait step.

In a DAG it is a task like any other, whose call reads as Waited[...]: its value or TimedOut, which a task taking it routes with .on(...) or expects in its parameter. A plain >> runs when it has its value (decision 324).

Parameters:
  • fn (Callable[P, R])

  • task_id (str)

  • options (_build.TaskOptions)

  • every (timedelta | None)

  • wait_for (RunOf | EventNamed | None)

  • call_timeout_ms (int | None)

fn(*args, **kwargs)

Calls the function, to await in a test.

A plain def poke runs on a thread, as its host calls it (decision 489).

Parameters:
  • *args (P.args) – Its arguments.

  • **kwargs (P.kwargs) – Its arguments.

Returns:

Its coroutine; what the step declares is in force while it runs.

Return type:

Coroutine[object, object, A]

schedr.sensors.sensor: Final = <schedr.sensors._Sensor object>

wait steps.

Type:

@sensor and @sensor.poke

Parameters:
Return type:

object

schedr.sensors.delay(wait, *, max_wait=None, task_id=None)

A wait step that waits wait from when it began: delay(timedelta(minutes=10)).

It counts from its first try’s start, so one tried again (its worker lost) waits only what is left. Its value is the moment it ended.

Parameters:
  • wait (timedelta) – How long; a run parameter too.

  • max_wait (timedelta | None) – Ends it with TimedOut past it; by default wait and a minute for a timedelta given here, else as for any wait step.

  • task_id (str | None) – Its ID; delay, numbered from the second on, if not given.

Returns:

the moment it ended, or TimedOut.

Return type:

The step’s output

Raises:

TypeError – For a negative wait.

schedr.sensors.until(at, *, max_wait=None, task_id=None)

A wait step that waits until a moment: until(timedelta(hours=2)) after the run’s.

A timedelta counts from the run’s planned_for, so a run caught up late, or one run again, doesn’t wait past it; a datetime (with a time zone) is that moment. One already past ends at once. Its value is the moment it ended.

Parameters:
  • at (datetime | timedelta) – The moment, or how long after dag_ctx.run.planned_for; a run parameter too.

  • max_wait (timedelta | None) – Ends it with TimedOut past it; as for any wait step by default.

  • task_id (str | None) – Its ID; until, numbered from the second on, if not given.

Returns:

the moment it ended, or TimedOut.

Return type:

The step’s output

Raises:

TypeError – For a moment without a time zone.