exuction_timeout使任务失败,但未发送电子邮件



如果任务持续时间超过我在dag的每个任务中配置execution_timeout的特定时间,我希望任务失败。然而,任务失败了,但我没有收到电子邮件通知。有人知道原因吗?如有任何帮助,我们将不胜感激。

default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime.today() - timedelta(days = 2),
'email':['email@company.com'],
'email_on_failure': True
}
[2022-10-27 03:06:42,587] {logging_mixin.py:112} INFO - [2022-10-27 03:06:42,585] {timeout.py:42} ERROR - Process timed out, PID: 15847
[2022-10-27 03:06:42,588] {bash_operator.py:140} INFO - Sending SIGTERM signal to bash process group
[2022-10-27 03:06:42,602] {taskinstance.py:1145} ERROR - Timeout, PID: 15847
Traceback (most recent call last):
File "/home/airflow_user/.local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 978, in _run_raw_task
result = task_copy.execute(context=context)
File "/home/airflow_user/.local/lib/python3.7/site-packages/airflow/operators/bash_operator.py", line 124, in execute
for line in iter(self.sub_process.stdout.readline, b''):
File "/home/airflow_user/.local/lib/python3.7/site-packages/airflow/utils/timeout.py", line 43, in handle_timeout
raise AirflowTaskTimeout(self.error_message)
airflow.exceptions.AirflowTaskTimeout: Timeout, PID: 15847

我可以看到任务变为红色。但即使使用email_on_failure配置,也不会发送电子邮件。

您尚未在airflow.cfg中配置smtp,您需要配置它:

[smtp]
smtp_host = #your smtp host
smtp_starttls = True
smtp_ssl = False
# Example: smtp_user = airflow
smtp_user = # your email to send
# Example: smtp_password = airflow
smtp_password = # App password
smtp_port = # your smtp port
smtp_mail_from = # your email to send
smtp_timeout = 30
smtp_retry_limit = 5

例如,如果您正在使用gmail:

[smtp]
smtp_host = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
# Example: smtp_user = airflow
smtp_user = example@gmail.com
# Example: smtp_password = airflow
smtp_password = #app password
smtp_port = 25
smtp_mail_from = example@gmail.com
smtp_timeout = 30
smtp_retry_limit = 5

注意:您可以在此处输入应用程序密码:https://support.google.com/mail/answer/185833?hl=en

Gmail端口可以是25465或587

最新更新