docker - 使用 docker 容器中的 Airflow 发送失败/重试电子邮件

标签 docker docker-compose smtp airflow

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

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

我无法让 Airflow 向我发送失败或重试的电子邮件。

我尝试了以下方法:

  • 使用 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
    
  • 在包含在 repo 中的 entrypoint.sh 脚本中编辑环境变量:
  • : "${AIRFLOW__SMTP__SMTP_HOST:="smtp-host"}"
    : "${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-host" ]; then
      AIRFLOW__SMTP__SMTP_HOST="smtp-host"
      AIRFLOW__SMTP__SMTP_PORT=25
    fi
    

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

    最佳答案

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

    关于docker - 使用 docker 容器中的 Airflow 发送失败/重试电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58736009/

    相关文章:

    docker - Neo4j docker-compose图像拒绝与应用程序的连接

    c# - 我如何在 Vista 上设置 smtp 以便我可以使用 System.Net.Mail?

    c# - 通过 .NET 代码发送电子邮件

    linux - 如何在无法启动的 Docker 容器中创建目录?

    docker - 运行 docker-compose up 后数据库权限被拒绝

    docker - Alpine Dockerfile --no-cache Vs 的优势。 rm/var/cache/apk/*

    php - 使用gmail smtp服务器发送电子邮件时smtp.gmail.com vs ssl ://smtp. gmail.com

    bash - Dockerfile不会替换文本,但是命令行会替换文本,可能是错误?

    php - Mysql 在 Docker 容器上退出

    c# - 在 Docker 中运行的 ASP .Net Core 2.0 中获取用户 IP