schedr.named_events¶
Events posted through the API: EventNamed (decision 354).
An outside system posts POST /api/v1/events (or schedr events post) with a name, a key
and data. Dag("ship", trigger=EventNamed("payment-completed")) starts a run per key posted
while it is live; wait_for(EventNamed("payment-completed", key=dag_ctx.params.order)) in a
run waits for the first of that key posted since the run was created.
- class schedr.named_events.EventNamed(name, key=None)¶
Bases:
TriggerEvents of one name posted through the API; with
key, the one of that key.As a DAG’s trigger,
Dag("ship", trigger=EventNamed("payment-completed")): each event posted while the DAG is live starts a run, one per key (a key seen before starts none), with the event asdag_ctx.event, planned for when it happened. In a run,wait_for(EventNamed("payment-completed", key=dag_ctx.params.order))waits for the first event of that name and key posted since the run was created (one posted before the step began waiting counts).- Parameters:
name (str)
key (str | None)
- name¶
The events’ name, written as a DAG ID is.
- Type:
str
- key¶
Which key
wait_forwaits for: a string, a run parameter,dag_ctx.run.id,dag_ctx.dag_id,dag_ctx.event.keyor an upstream task’s output;None: any. A trigger takes none: every key starts a run.- Type:
str | None
- to_model()¶
The trigger in DAG JSON.
- Returns:
Its model.
- Raises:
ValueError – For a key: a trigger starts a run for every key.
- Return type:
- schedr.named_events.wait_for_event(event, *, max_wait=None, task_id=None)¶
wait_for(EventNamed(...)): a step the master ends when the event comes.- Parameters:
event (EventNamed) – Which event, and its key.
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_<name>, numbered from the second on, if not given.
- Returns:
the event, read as its value, or
TimedOut.- Return type:
The step’s output