在过去的两天中,我一直在研究一个错误,经过所有调试和在黑暗中拍摄之后,它开始使我吃光。
气流似乎不均匀,触发邮件,我将说明如何:
这是我的airflow.cfg设置:
[email]
email_backend = airflow.utils.email.send_email_smtp
SENDGRID_MAIL_FROM=<random-email-id@doesntexist.com>
#SENDGRID_API_KEY=...
[smtp]e
smtp_host = smtp.sendgrid.net
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
smtp_user = apikey
smtp_password = ...
smtp_port = 465
smtp_mail_from = <random-email-id@doesntexist.com>
然后,我看到它所引用的文件是utils / email.py,其方法为:send_email_smtp
def send_email(to, subject, html_content, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed'):
"""
Send email using backend specified in EMAIL_BACKEND.
"""
path, attr = configuration.get('email', 'EMAIL_BACKEND').rsplit('.', 1)
module = importlib.import_module(path)
backend = getattr(module, attr)
return backend(to, subject, html_content, files=files, dryrun=dryrun, cc=cc, bcc=bcc, mime_subtype=mime_subtype)
def send_email_smtp(to, subject, html_content, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed'):
"""
Send an email with html content
>>> send_email('test@example.com', 'foo', '<b>Foo</b> bar', ['/dev/null'], dryrun=True)
"""
SMTP_MAIL_FROM = configuration.get('smtp', 'SMTP_MAIL_FROM')
TITU
to = get_email_address_list(to)
log.info("!!!!#@Q@$%%%^%!@!@!@!@!@!@!@!@!@!@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
msg = MIMEMultipart(mime_subtype)
msg['Subject'] = subject
msg['From'] = SMTP_MAIL_FROM
msg['To'] = ", ".join(to)
recipients = to
if cc:
cc = get_email_address_list(cc)
msg['CC'] = ", ".join(cc)
recipients = recipients + cc
if bcc:
# don't add bcc in header
bcc = get_email_address_list(bcc)
recipients = recipients + bcc
msg['Date'] = formatdate(localtime=True)
mime_text = MIMEText(html_content, 'html')
msg.attach(mime_text)
for fname in files or []:
basename = os.path.basename(fname)
with open(fname, "rb") as f:
part = MIMEApplication(
f.read(),
Name=basename
)
part['Content-Disposition'] = 'attachment; filename="%s"' % basename
part['Content-ID'] = '<%s>' % basename
msg.attach(part)
#send_MIME_email(SMTP_MAIL_FROM, recipients, msg, dryrun)
send_MIME_email_sendgrid(SMTP_MAIL_FROM, recipients, msg, dryrun)
def send_MIME_email_sendgrid(e_from, e_to, mime_msg, dryrun=False):
log = LoggingMixin().log
sg = SendGridAPIClient('..<my-sendgrid-key>..')
sg.send(mime_msg)
log.info("Sent an alert email to %s", e_to)
即使'log.info('!#!@ $#@%@%')也没有在上面记录。
请帮助。真的无法正确解决此问题-我正在使用Airflow 1.9.0,并在其顶部安装了sendgrid-默认情况下,Airflow 1.10.0及以下版本不带有sendgrid依赖项
答案 0 :(得分:0)
这确实被称为。 我们需要两个方面:
将任务指定为:
email_on_failure=True,
email=['i.wont@tell.com']
我们的问题在于与sendgrid进行身份验证,该服务用户从中运行气流Web服务器/调度程序。