Apache 气流仅向列表中的第一人发送 sla 未命中电子邮件 [英] Apache airflow sends sla miss emails only to first person on the list

查看:33
本文介绍了Apache 气流仅向列表中的第一人发送 sla 未命中电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Apache Airflow,我希望它发送有关 sla 未命中的电子邮件通知.我将电子邮件地址存储为气流变量,并且我有一个 dag,其中一个任务使用 EmailOperator 发送电子邮件.

I use Apache Airflow and I would like it to send email notifications on sla miss. I store email adresses as airflow variable, and I have a dag which one of its tasks sends Email using EmailOperator.

问题来了,因为当我的发送邮件任务运行到所有收件人时,它会发送电子邮件,它只会将 sla 未命中通知发送到列表中的第一个地址,在我的示例中意味着 test1@test.com.

And here comes the issue because however It sends emails when my send-mail task is run to all the recipients, It do sends sla miss notifaction only to the first adress on the list which in my example means test1@test.com.

这是一些错误,还是为什么它不起作用?

Is this some bug, or why it's not working ?

这是我的 dag 和 airlfow 变量:

Here's my dag and airlfow variable:

from airflow import DAG
from datetime import datetime, timedelta
from airflow.operators.email_operator import EmailOperator
from airflow.models import Variable
from airflow.operators.slack_operator import SlackAPIPostOperator

email = Variable.get("test_recipients")

args = {
    'owner': 'airflow'
    , 'depends_on_past': False
    , 'start_date': datetime(2018, 8, 20, 0, 0)
    , 'retries': 0
    , 'email': email
    , 'email_on_failure': True
    , 'email_on_retry': True
    , 'sla': timedelta(seconds=1)
}

dag = DAG('sla-email-test'
          , default_args=args
          , max_active_runs=1
          , schedule_interval="@daily")

....

t2 = EmailOperator(
    dag=dag,
    task_id="send-email",
    to=email,
    subject="Testing",
    html_content="<h3>Welcome to Airflow</h3>"
)

推荐答案

是的,Airflow 目前在发送 SLA 电子邮件时存在一个错误 - 代码路径没有正确地按 拆分字符串, 就像任务失败电子邮件一样.

Yes, there is currently a bug in Airflow when it comes to sending the SLA emails - that code path doesn't correctly split a string by , like task failure emails do.

现在的简短工作是使您的变量成为一个列表(即具有 ["test1@test.com","test2@test.com"] 的值并像访问它一样访问它:

The short work around right now is to make your variable a list (i.e. with a value of ["test1@test.com","test2@test.com"] and access it like:

email = Variable.get("test_recipients", deserialize_json=True)

这应该适用于两种情况(SLA 和任务电子邮件)

That should work in both cases (SLA, and task emails)

这篇关于Apache 气流仅向列表中的第一人发送 sla 未命中电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆