Sub topic 13
Notifying on failure
This chapter assumes you can create a multi-task job, set retries and timeouts, and read a run's status page. Notifications tell people when a run needs attention, so a failed 06:00 pipeline does not sit unnoticed until a dashboard looks wrong.
Where notifications are set
You can configure notifications at two levels:
- Job level: events for the whole run, such as start, success, failure, and duration warning.
- Task level: events for a single task, so the owner of one notebook gets only the alerts that concern them.
Destinations can be email addresses or workspace notification destinations such as Slack, Microsoft Teams, PagerDuty, or a webhook. An administrator creates the notification destinations. You then select them in the job.
The events you can subscribe to
| Event | Fires when |
|---|---|
| `on_start` | A run begins |
| `on_success` | A run finishes successfully |
| `on_failure` | A run ends in a failed state |
| `on_duration_warning_threshold_exceeded` | A run takes longer than the warning threshold you set |
| `on_streaming_backlog_exceeded` | A streaming run falls behind the backlog threshold you set |
Most batch jobs only need on_failure. Add the duration warning for jobs that hang quietly instead of failing.
Example in a bundle
This fragment extends the job from the earlier chapter on jobs as code. The job emails the data team on failure, and the ingest task has its own alert:
resources:
jobs:
daily_sales:
name: daily-sales-pipeline
email_notifications:
on_failure:
- [email protected]
tasks:
- task_key: ingest
notebook_task:
notebook_path: ../src/ingest.ipynb
email_notifications:
on_failure:
- [email protected]Retries and notification timing
Retries affect when you are notified. A task with max_retries: 2 can fail twice and then succeed. In that case the run succeeds and no failure alert goes out for the task. By default, task-level failure notifications fire on each failed attempt. Job-level on_failure fires only when the whole run fails, after retries are used up. Check the behavior in your workspace before you rely on it, because this is a common source of surprise.
Common mistakes
- Alerting only on failure for a job that can hang. A stuck task never fails until its timeout. Set a timeout and a duration warning threshold.
- Sending alerts to one person's inbox. Use a team distribution list or a shared channel destination so alerts survive vacations and role changes.
- Duplicate alerts. The same address at job and task level can produce two messages for one problem. Pick one level per recipient.
- Forgetting
on_successnoise. Success emails on a daily job are ignored within a week. Leave them off unless a downstream team needs them.
Exercise
Exercise
A job has max_retries: 2 on the ingest task and an on_failure email at the job level. ingest fails on its first attempt and succeeds on the second. Does the job-level failure email go out? What would you add to be told when a run hangs for hours?
Show answer
No. The run ends successfully, so the job-level on_failure event does not fire. To catch a hang, set a task or job timeout so the run eventually fails, and add a duration warning threshold with on_duration_warning_threshold_exceeded notifications so someone hears about it before the timeout.