在docker容器中出现气流失败/重试时发送电子邮件

我正在尝试使用在此处找到的LocalExecutor.yml文件来运行puckel airflow docker容器:

https://github.com/puckel/docker-airflow

我无法获得成功,无法通过电子邮件发送失败或重试的电子邮件。

我尝试了以下操作:

  1. 使用smtp主机名编辑配置文件
[smtp]
# If you want airflow to send emails on retries,failure,and you want to use
# the airflow.utils.email.send_email_smtp function,you have to configure an
# smtp server here
smtp_host = smtp@mycompany.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user = airflow
# smtp_password = airflow
smtp_port = 25
smtp_mail_from = myname@mycompany.com
  1. 在存储库中包含的entrypoint.sh脚本中编辑环境变量:
: "${AIRFLOW__SMTP__SMTP_HOST:="smtp-int.teslamotors.com"}"
: "${AIRFLOW__SMTP__SMTP_PORT:="25"}"
# Defaults and back-compat
: "${AIRFLOW_HOME:="/usr/local/airflow"}"
: "${AIRFLOW__CORE__FERNET_KEY:=${FERNET_KEY:=$(python -c "from cryptography.fernet import Fernet; FERNET_KEY = Fernet.generate_key().decode(); print(FERNET_KEY)")}}"
: "${AIRFLOW__CORE__EXECUTOR:=${EXECUTOR:-Sequential}Executor}"



export \
  AIRFLOW_HOME \
  AIRFLOW__CELERY__BROKER_URL \
  AIRFLOW__CELERY__RESULT_BACKEND \
  AIRFLOW__CORE__EXECUTOR \
  AIRFLOW__CORE__FERNET_KEY \
  AIRFLOW__CORE__LOAD_EXAMPLES \
  AIRFLOW__CORE__SQL_ALCHEMY_CONN \
  AIRFLOW__SMTP__SMTP_HOST \
  AIRFLOW__SMTP__SMTP_PORT \

if [ "$AIRFLOW__SMTP__SMTP_HOST" != "smtp-int.teslamotors.com" ]; then
  AIRFLOW__SMTP__SMTP_HOST="smtp-int.teslamotors.com"
  AIRFLOW__SMTP__SMTP_PORT=25
fi

我目前正在运行的dag故意失败了,但是我从未收到有关重试或失败的警报。

zhouhsmp3 回答:在docker容器中出现气流失败/重试时发送电子邮件

您不需要执行步骤1和2。在docker-compose.yml中指定环境变量。 另外,请确保您已在操作员中启用了失败发送电子邮件, 就像在这里:https://gist.githubusercontent.com/aawgit/0753b3ef1d715257e442ceafbc8583d3/raw/fa45caa9150e08654d476c2d619ab50615942b46/email-notification-on-task-failure.py

,

设置以下变量以使邮件功能正常工作。 它取决于SMTP邮件服务器的配置。 用户名和密码应正确设置。

  • 如果使用docker-compose,则在docker-compose.yml中设置以下变量将自动更新气流变量:
- AIRFLOW__SMTP__SMTP_HOST=smtp_host
- AIRFLOW__SMTP__SMTP_PORT=25_?_the_smtp_port_used_smtp_host
- AIRFLOW__SMTP__SMTP_USER=mail_user_name_of_your_app
- AIRFLOW__SMTP__SMTP_PASSWORD=mail_user_password_of_your_app
- AIRFLOW__SMTP__SMTP_MAIL_FROM=mail_user_name_of_your_app@mail.server.name
  • 类似地,如果手动启动docker,请将以下变量设置为环境变量:
AIRFLOW__SMTP__SMTP_HOST=smtp_host
AIRFLOW__SMTP__SMTP_PORT=25_?_the_smtp_port_used_smtp_host
AIRFLOW__SMTP__SMTP_USER=mail_user_name_of_your_app
AIRFLOW__SMTP__SMTP_PASSWORD=mail_user_password_of_your_app
AIRFLOW__SMTP__SMTP_MAIL_FROM=mail_user_name_of_your_app@mail.server.name

export AIRFLOW__SMTP__SMTP_HOST AIRFLOW__SMTP__SMTP_PORT AIRFLOW__SMTP__SMTP_USER AIRFLOW__SMTP__SMTP_PASSWORD AIRFLOW__SMTP__SMTP_MAIL_FROM

# Then bring up docker:
docker run your_docker...
本文链接:https://www.f2er.com/3149907.html

大家都在问