airflow-scheduler - 气流将自定义数据附加到电子邮件警报
问题描述
我想在失败时将运行手册 URL 附加到气流电子邮件警报中。默认电子邮件发送其他有用的信息,例如气流日志链接,我不想放弃它。我怎样才能做到这一点。
我探索了电子邮件运营商,但似乎它创建了一封新电子邮件,现在我收到 2 封电子邮件,其中一封用于失败的 dag,另一封来自电子邮件运营商。
有办法解决吗?
failure_email = EmailOperator (
task_id='failure-email',
name='failure-email',
to=['oncall@gmail.com'],
subject="T3 Failed",
html_content='<a>https://path/to/runbook</a>',
namespace= ,
dag=dag
)
解决方案
您可以通过在 conf 中设置变量来自定义气流电子邮件内容,该html_content_template
变量的值应该是 jinja2 文件的路径。
例如:
气流.cfg -
[email]
html_content_template = /path/to/template
/路径/到/模板 -
Try {{try_number}} out of {{max_tries + 1}}<br>
Exception:<br>{{exception_html}}<br>
Log: <a href="{{ti.log_url}}">Link</a><br>
Host: {{ti.hostname}}<br>
Log file: {{ti.log_filepath}}<br>
Mark success: <a href="{{ti.mark_success_url}}">Link</a><br>
Runbook: <a>https://path/to/runbook</a>
(气流电子邮件的默认内容取自https://github.com/apache/airflow/blob/6e269570cd6dd2d434a3c63ca0db9f1a59dea847/airflow/models/taskinstance.py#L1263)。
推荐阅读
- android - Flutter 创建即时启用的 Android App Bundle
- python-3.x - 如何将for循环代码更改为pythonic方式
- c# - ApplicationData 在控制台中使用 UWP 参数
- javascript - useEffect(fn, []) 中包裹的代码和 useEffect(fn, []) 之外的代码有什么区别?
- python - 如何使用 python json 从 JSON 文件中提取特定对象
- android - 如何在活动中打开 BottomNavigationView 的片段?
- r - dplyr 将字符强制转换为因子
- spring - 如何使用 Junit 和 Mockito 测试 DaoImpl 方法
- r - 为 ARIMA(1 1 0)(0 1 0) 12 编写数学方程
- java - 通过@Configuration、@Bean 和@Component 进行Spring 依赖注入