Skip to content

Move email notifications from scheduler to DAG processor - #55238

Merged
kaxil merged 1 commit into
apache:mainfrom
astronomer:move-sending-email
Sep 4, 2025
Merged

kaxil merged 1 commit into
apache:mainfrom
astronomer:move-sending-email

Conversation

@kaxil

@kaxil kaxil commented Sep 4, 2025 •

Copy link
Copy Markdown
Member

Email notifications for task failures and retries are now handled by the DAG processor instead of the scheduler, maintaining the architectural principle that the scheduler should never execute user code - even if it is just sending emails.

Key changes:

  • Add EmailCallbackRequest for failure/retry notifications
  • Update scheduler to send email callback requests via executor to the DB
  • Remove email handling from TaskInstance.handle_failure method
  • Simplify fetch_handle_failure_context to remove template context usage

This ensures the scheduler remains isolated from user code execution while preserving email notification functionality through the existing callback request pattern used for task and DAG callbacks.

Part of #51546
Closes #55211

You can run a task with sleep and kill the API-server to test it
Scheduler logs:
image

Dag Processor logs:

{"timestamp":"2025-09-04T01:29:37.476068","level":"info","event":"Filling up the DagBag from /files/dags/example_py.py","logger":"airflow.models.dagbag.DagBag"}
{"timestamp":"2025-09-04T01:29:37.498998","level":"info","event":"Sending failure email for task simplest_dag","dag_id":"as","run_id":"manual__2025-09-04T01:29:22.437699+00:00","logger":"task"}
{"timestamp":"2025-09-04T01:29:38.473826","level":"info","event":"Email alerting: attempt 1","logger":"airflow.utils.email"}

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@kaxil kaxil added this to the Airflow 3.1.0 milestone Sep 4, 2025
@kaxil
kaxil requested a review from uranusjr September 4, 2025 00:52
@kaxil
kaxil force-pushed the move-sending-email branch 2 times, most recently from d5bfe86 to 091756d Compare September 4, 2025 01:56
@kaxil
kaxil requested a review from amoghrajesh as a code owner September 4, 2025 01:56
@kaxil
kaxil force-pushed the move-sending-email branch from 091756d to aa2725e Compare September 4, 2025 02:08

@eladkal eladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish I pushed more on removing the special email handling in favor of regular notifier as part of Airflow 3.

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@kaxil

kaxil commented Sep 4, 2025

Copy link
Copy Markdown
Member Author

I really wish I pushed more on removing the special email handling in favor of regular notifier as part of Airflow 3.

Me too :(

@kaxil
kaxil force-pushed the move-sending-email branch from aa2725e to 8289b41 Compare September 4, 2025 10:18
Email notifications for task failures and retries are now handled by the DAG
processor instead of the scheduler, maintaining the architectural principle
that the scheduler should never execute user code - even if it is just sending emails.

Key changes:
- Add `EmailCallbackRequest` for failure/retry notifications
- Update scheduler to send email callback requests via executor to the DB
- Remove email handling from TaskInstance.handle_failure method
- Simplify fetch_handle_failure_context to remove template context usage

This ensures the scheduler remains isolated from user code execution while
preserving email notification functionality through the existing callback
request pattern used for task and DAG callbacks.

Part of apache#52141
closes apache#55211
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler crashing when executed mapped tasks with kubernetes executor

4 participants