schedr.notify¶
Notifications (decisions 408, 409, 417-423): which channels a DAG tells of which events.
A DAG names channels in notify=: a string names a channel of the server’s configuration,
a WebhookChannel is the DAG’s own. A list gives each the server’s default events;
a dict chooses them:
from schedr import Dag, Notify, WebhookChannel, notify
relay = WebhookChannel(
"relay",
url="https://relay.example.com/schedr",
body={"title": t"{notify.dag} {notify.event}", "tasks": notify.failed_tasks},
)
with Dag("etl", notify={relay: [Notify.RUN_FAILED], "ops-slack": [Notify.RUN_RECOVERED]}):
...
A body is JSON whose values may be placeholders (notify.dag) or t-strings over them;
the master fills them in when it queues a notification, without running any code. Plain
values in a t-string are written in when the file loads. A DAG’s webhook URL is in the DAG
file, so it must hold no secret: a Slack or Teams webhook URL is one, and belongs to a server
webhook (decision 425).
A task sends a message of its own to a channel of its DAG with WebhookChannel.send()
or schedr.api.notify() (schedr task-ctx notify from a command).
- class schedr.notify.Notify(*values)¶
Bases:
StrEnumAn event a channel is told of (decision 408).
- RUN_FAILED = 'RUN_FAILED'¶
A run ended
failed(a cancel with a failure included). The default.
- TASK_FAILED = 'TASK_FAILED'¶
A task failed after its last retry.
- TASK_RETRY = 'TASK_RETRY'¶
An attempt failed and will be retried.
- RUN_CANCELLED = 'RUN_CANCELLED'¶
A run was cancelled, with no failure.
- RUN_SUCCEEDED = 'RUN_SUCCEEDED'¶
A run ended
success.
- RUN_RECOVERED = 'RUN_RECOVERED'¶
A run succeeded after the DAG’s previous run failed.
- TRIGGER_FAILING = 'TRIGGER_FAILING'¶
The DAG’s trigger kept failing, or its generator returned.
- LATE_CLEANUP_FAILED = 'LATE_CLEANUP_FAILED'¶
A cleanup that ran after its run had ended failed.
- class schedr.notify.Placeholder(name, path=())¶
Bases:
objectA value the master fills in a message body:
notify.dag,notify.data["rows"].It has no value in the DAG file: use it in a body, bare (keeping the value’s JSON type) or in a t-string (as text).
- Parameters:
name (str)
path (tuple[str | int, ...])
- to_json()¶
The reference as DAG JSON.
- Returns:
{"name": ...}, with"path"when it has one.- Return type:
dict[str, object]
- class schedr.notify.WebhookChannel(name, *, url, body=None)¶
Bases:
objectA webhook the DAG defines:
WebhookChannel("relay", url=..., body=...).Its URL must start with one of the server’s
[notifications] dag_urls(checked by the master), and it is written in the DAG file: it must hold no secret (decision 425). A secret webhook (Slack’s, Teams’) is a server webhook, named by a string.- Parameters:
name (str) – Its name, unique among the DAG’s channels;
sendandschedr task-ctx notifyname it.url (str) – Where it posts (
https://orhttp://).body (object) – The JSON it posts, with placeholders (
notify.dag) and t-strings over them;None: schedr’s fixed JSON, with a top-leveltext.
- Raises:
ValueError – For a bad name or URL.
TypeError – For a body value that isn’t JSON, a placeholder or a t-string over them.
- schedr.notify.attempt: Final = notify.attempt¶
The attempt’s number, for task events and
send; null otherwise.
- schedr.notify.dag: Final = notify.dag¶
The DAG’s ID.
- schedr.notify.data: Final = notify.data¶
its
data; null in event notifications.- Type:
A task’s own
send
- schedr.notify.event: Final = notify.event¶
The event’s name (
RUN_FAILED;MESSAGEfor a task’s ownsend).
- schedr.notify.failed_tasks: Final = notify.failed_tasks¶
a list of
{"task": ..., "error": ...}.- Type:
The failed tasks
- schedr.notify.link: Final = notify.link¶
The link to the run in the UI (
[notifications] ui_url), or null.
- schedr.notify.planned_for: Final = notify.planned_for¶
The run’s planned time (UTC, RFC 3339), or null.
- schedr.notify.run: Final = notify.run¶
The run’s ID.
- schedr.notify.state: Final = notify.state¶
The run’s or the task’s state.
- schedr.notify.task: Final = notify.task¶
The task’s ID, for task events and
send; null otherwise.
- schedr.notify.text: Final = notify.text¶
schedr’s one-line summary; for a task’s own
send, itstext.
- schedr.notify.time: Final = notify.time¶
When the event happened (UTC, RFC 3339).
- schedr.notify.zone: Final = notify.zone¶
The DAG’s time zone.