Skip to content

Commit a0b7487

Browse files
committed
Improve default task failure email template for readability
Replace the current default task failure email template with a modern, operator-friendly version that addresses readability issues. - Add professional HTML template with dark theme matching Airflow UI - Include structured task details (DAG, task, run ID, attempt, host, tags) - Add clear exception formatting in highlighted box - Include action buttons for View Log and Mark Success - Provide plain text fallback for non-HTML email clients - Add Airflow 3.x compatibility with conditional rendering - Maintain backward compatibility (custom templates still work) - Add Apache License headers to all template files closes: apache#61667
1 parent d4829eb commit a0b7487

4 files changed

Lines changed: 149 additions & 129 deletions

File tree

Lines changed: 107 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,113 @@
1+
{#
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
#}
19+
120
<!DOCTYPE html>
221
<html>
3-
<body style="margin:0;padding:0;background-color:#171c2f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif">
4-
<table width="100%" cellpadding="0" cellspacing="0" style="padding:64px 24px 72px 24px">
5-
<tr>
6-
<td align="center">
7-
<table width="600" cellpadding="0" cellspacing="0">
8-
<!-- Logo -->
9-
<tr>
10-
<td align="center" style="padding-bottom:48px">
11-
<img src="https://cwiki.apache.org/confluence/download/attachments/145723561/airflow_transparent.png" width="56" height="56" alt="Airflow" style="display:block;width:56px;height:56px">
12-
</td>
13-
</tr>
14-
<!-- Status -->
15-
<tr>
16-
<td style="padding-bottom:0">
17-
<table cellpadding="0" cellspacing="0">
18-
<tr>
19-
<td style="font-size:13px;color:#ef4444;line-height:1;vertical-align:middle">&#9679;</td>
20-
<td style="padding-left:8px">
21-
<span style="font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:0.08em;color:#ef4444">Task Failed</span>
22-
</td>
23-
</tr>
24-
</table>
25-
</td>
26-
</tr>
27-
<!-- DAG name -->
28-
<tr>
29-
<td style="padding-bottom:6px;padding-top:8px">
30-
<span style="font-size:28px;font-weight:700;color:#e8ecf4;letter-spacing:-0.02em">{{ti.dag_id}}</span>
31-
</td>
32-
</tr>
33-
<!-- Task name -->
34-
<tr>
35-
<td style="padding-bottom:24px">
36-
<span style="font-size:18px;color:#8896b3">{{ti.task_id}}</span>
37-
</td>
38-
</tr>
39-
<!-- Details card -->
40-
<tr>
41-
<td style="padding-bottom:24px">
42-
<table width="100%" cellpadding="0" cellspacing="0" style="background-color:#1f2539;border-radius:8px;border:1px solid #2d3450">
43-
<tr>
44-
<td style="padding:24px">
45-
<table width="100%" cellpadding="0" cellspacing="0" style="font-size:15px;line-height:1.5">
46-
<tr>
47-
<td style="padding:8px 0;color:#8896b3;width:100px;vertical-align:top">Run</td>
48-
<td style="padding:8px 0;color:#e8ecf4">{{ti.run_id}}</td>
49-
</tr>
50-
<tr>
51-
<td colspan="2" style="border-bottom:1px solid #2d3450;font-size:0;line-height:0">&nbsp;</td>
52-
</tr>
53-
<tr>
54-
<td style="padding:8px 0;color:#8896b3;vertical-align:top">Attempt</td>
55-
<td style="padding:8px 0;color:#e8ecf4">{{try_number}} of {{max_tries + 1}}</td>
56-
</tr>
57-
<tr>
58-
<td colspan="2" style="border-bottom:1px solid #2d3450;font-size:0;line-height:0">&nbsp;</td>
59-
</tr>
60-
<tr>
61-
<td style="padding:8px 0;color:#8896b3;vertical-align:top">Host</td>
62-
<td style="padding:8px 0;color:#e8ecf4;font-family:'SF Mono',SFMono-Regular,Consolas,'Liberation Mono',Menlo,monospace;font-size:14px">{{ti.hostname}}</td>
63-
</tr>
64-
{% if dag and dag.tags %}
65-
<tr>
66-
<td colspan="2" style="border-bottom:1px solid #2d3450;font-size:0;line-height:0">&nbsp;</td>
67-
</tr>
68-
<tr>
69-
<td style="padding:8px 0;color:#8896b3;vertical-align:top">Tags</td>
70-
<td style="padding:8px 0">
71-
{% for tag in dag.tags|sort %}<span style="display:inline-block;background-color:#2d3450;color:#a3b3d1;padding:3px 12px;border-radius:20px;font-size:13px;font-weight:500;margin:2px 4px 2px 0">{{tag}}</span>{% endfor %}
22+
<head>
23+
<meta charset="UTF-8">
24+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
25+
</head>
26+
<body style="margin:0;padding:0;background-color:#171c2f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif">
27+
<table width="100%" cellpadding="0" cellspacing="0" style="padding:64px 24px 72px 24px">
28+
<tr>
29+
<td align="center">
30+
<table width="600" cellpadding="0" cellspacing="0">
31+
<!-- Logo -->
32+
<tr>
33+
<td align="center" style="padding-bottom:48px">
34+
<img src="https://cwiki.apache.org/confluence/download/attachments/145723561/airflow_transparent.png?api=v2" alt="Airflow" width="120" height="120">
7235
</td>
73-
</tr>
74-
{% endif %}
75-
</table>
76-
</td>
77-
</tr>
78-
</table>
79-
</td>
80-
</tr>
81-
<!-- Exception card -->
82-
<tr>
83-
<td style="padding-bottom:32px">
84-
<table width="100%" cellpadding="0" cellspacing="0" style="background-color:#2a1215;border-radius:8px;border:1px solid #4a2025">
85-
<tr>
86-
<td style="padding:20px 24px;font-family:'SF Mono',SFMono-Regular,Consolas,'Liberation Mono',Menlo,monospace;font-size:14px;line-height:1.7;color:#fca5a5;word-break:break-word">
87-
{{exception_html}}
88-
</td>
89-
</tr>
90-
</table>
91-
</td>
92-
</tr>
93-
<!-- Actions -->
94-
<tr>
95-
<td>
96-
<table cellpadding="0" cellspacing="0">
97-
<tr>
98-
{% if ti.log_url %}
99-
<td style="padding-right:12px">
100-
<a href="{{ti.log_url}}" style="display:inline-block;padding:8px 28px;background-color:#3b82f6;color:#ffffff;text-decoration:none;border-radius:4px;font-size:15px;font-weight:600">View Log</a>
101-
</td>
102-
{% endif %}
103-
{% if ti.mark_success_url %}
104-
<td>
105-
<a href="{{ti.mark_success_url}}" style="display:inline-block;padding:8px 28px;background-color:transparent;color:#a3b3d1;text-decoration:none;border-radius:4px;font-size:15px;font-weight:500;border:1px solid #2d3450">Mark Success</a>
106-
</td>
107-
{% endif %}
108-
</tr>
109-
</table>
36+
</tr>
37+
<!-- Status -->
38+
<tr>
39+
<td style="padding-bottom:0">
40+
<table cellpadding="0" cellspacing="0" style="padding:0 0 8px 0">
41+
<tr>
42+
<td style="font-size:13px;color:#ef4444;line-height:1;vertical-align:middle">&#9679;</td>
43+
<td style="padding-left:8px">
44+
<span style="font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:0.08em;color:#ef4444">TASK FAILED</span>
45+
</td>
46+
</tr>
47+
</table>
48+
</td>
49+
</tr>
50+
<!-- DAG Name -->
51+
<tr>
52+
<td style="font-size:32px;font-weight:600;color:#ffffff;padding-bottom:8px">{{ti.dag_id}}</td>
53+
</tr>
54+
<!-- Task Name -->
55+
<tr>
56+
<td style="font-size:18px;color:#94a3b8;padding-bottom:32px">{{ti.task_id}}</td>
57+
</tr>
58+
<!-- Details Card -->
59+
<tr>
60+
<td>
61+
<table width="100%" cellpadding="0" cellspacing="0" style="background-color:#1e293b;border-radius:8px;padding:24px">
62+
<tr>
63+
<td style="padding:8px 0;color:#94a3b8;font-size:14px;width:120px">Run</td>
64+
<td style="padding:8px 0;color:#e8ecf4">{{ti.run_id}}</td>
65+
</tr>
66+
<tr>
67+
<td style="padding:8px 0;color:#94a3b8;font-size:14px">Attempt</td>
68+
<td style="padding:8px 0;color:#e8ecf4">{{try_number}} of {{max_tries}}</td>
69+
</tr>
70+
<tr>
71+
<td style="padding:8px 0;color:#94a3b8;font-size:14px">Host</td>
72+
<td style="padding:8px 0;color:#e8ecf4;font-family:monospace;font-size:13px">{{ti.hostname}}</td>
73+
</tr>
74+
{% if dag and dag.tags %}
75+
<tr>
76+
<td style="padding:8px 0;color:#94a3b8;font-size:14px;vertical-align:top">Tags</td>
77+
<td style="padding:8px 0">
78+
{% for tag in dag.tags %}
79+
<span style="display:inline-block;background-color:#334155;color:#cbd5e1;padding:4px 12px;border-radius:12px;font-size:13px;margin-right:8px;margin-bottom:4px">{{tag}}</span>
80+
{% endfor %}
81+
</td>
82+
</tr>
83+
{% endif %}
84+
</table>
85+
</td>
86+
</tr>
87+
<!-- Exception -->
88+
<tr>
89+
<td style="padding-top:24px">
90+
<table width="100%" cellpadding="0" cellspacing="0" style="background-color:#7d1f1f;border-radius:8px;padding:20px">
91+
<tr>
92+
<td style="color:#fca5a5;font-family:monospace;font-size:13px;line-height:1.6;white-space:pre-wrap">{{exception_html|safe}}</td>
93+
</tr>
94+
</table>
95+
</td>
96+
</tr>
97+
<!-- Actions -->
98+
<tr>
99+
<td style="padding-top:32px">
100+
{% if ti.log_url %}
101+
<a href="{{ti.log_url}}" style="display:inline-block;background-color:#4a9eff;color:#ffffff;padding:12px 32px;border-radius:6px;text-decoration:none;font-weight:600;font-size:15px;margin-right:16px">View Log</a>
102+
{% endif %}
103+
{% if ti.mark_success_url %}
104+
<a href="{{ti.mark_success_url}}" style="color:#94a3b8;text-decoration:none;font-size:15px">Mark Success</a>
105+
{% endif %}
106+
</td>
107+
</tr>
108+
</table>
110109
</td>
111-
</tr>
112-
</table>
113-
</td>
114-
</tr>
115-
</table>
110+
</tr>
111+
</table>
116112
</body>
117113
</html>

‎airflow-core/src/airflow/templates/email/task_failure_body.txt‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
AIRFLOW TASK FAILURE
2-
====================
1+
{#
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
39

4-
● TASK FAILED
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
#}
19+
⚠ TASK FAILED
520

621
DAG: {{ti.dag_id}}
722
Task: {{ti.task_id}}
823

9-
Details
10-
-------
11-
Run: {{ti.run_id}}
12-
Attempt: {{try_number}} of {{max_tries + 1}}
13-
Host: {{ti.hostname}}
14-
{% if dag and dag.tags %}Tags: {% for tag in dag.tags|sort %}{{tag}}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}
24+
Run: {{ti.run_id}}
25+
Attempt: {{try_number}} of {{max_tries}}
26+
Host: {{ti.hostname}}
27+
{% if dag and dag.tags %}Tags: {{dag.tags|join(', ')}}{% endif %}
1528

16-
Exception
17-
---------
18-
{{exception}}
29+
Exception:
30+
{{exception_html|safe}}
1931

20-
Actions
21-
-------
2232
{% if ti.log_url %}View Log: {{ti.log_url}}{% endif %}
2333
{% if ti.mark_success_url %}Mark Success: {{ti.mark_success_url}}{% endif %}
24-
25-
---
26-
Apache Airflow
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1+
{#
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
#}
119
Airflow alert: {{ti.dag_id}} / {{ti.task_id}} failed

‎task-sdk/src/airflow/sdk/execution_time/task_runner.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# KIND, either express or implied. See the License for the
1616
# specific language governing permissions and limitations
1717
# under the License.
18-
"""The entrypoint for the actual task execution process."""
1918

2019
from __future__ import annotations
2120

0 commit comments

Comments
 (0)