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:
EnumThe type of
NOT_YET: what@sensor.pokereturns while it has nothing.
- schedr.sensors.NOT_YET: Final = NotYet.NOT_YET¶
What a
@sensor.pokefunction returns until it has its value (soNoneis 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 returnedNOT_YET: the master then waits for a later matching run (itsNOT_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_waitofStepDefaults, 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:
PathforPath | NotYet; the annotation itself ifNotYetisn’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
@sensoror@sensor.poke: a wait step.In a DAG it is a task like any other, whose call reads as
Waited[...]: its value orTimedOut, 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
awaitin a test.A plain
defpoke 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:
@sensorand@sensor.poke- Parameters:
fn (Callable[..., object] | None)
wait_for (RunOf | EventNamed | None)
timeout (timedelta | None)
options (Unpack[SensorOptions])
- Return type:
object
- schedr.sensors.delay(wait, *, max_wait=None, task_id=None)¶
A wait step that waits
waitfrom 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
TimedOutpast it; by defaultwaitand a minute for atimedeltagiven 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
timedeltacounts from the run’splanned_for, so a run caught up late, or one run again, doesn’t wait past it; adatetime(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
TimedOutpast 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.