Skip to content

Instantly share code, notes, and snippets.

@neybapps
Created May 29, 2020 05:04
Show Gist options
  • Save neybapps/844d2a96263a89a28eb70a356260d308 to your computer and use it in GitHub Desktop.
Save neybapps/844d2a96263a89a28eb70a356260d308 to your computer and use it in GitHub Desktop.
failure_function for airflow email reporting
from airflow.operators.email_operator import EmailOperator
def report_failure(context):
subject = 'Airflow critical: {{ti}}'
html_content = (
'Try {{try_number}} out of {{max_tries + 1}}<br>'
'Exception:<br>{{exception_html}}<br>'
'Log: <a href="{{ti.log_url}}">Link</a><br>'
'Host: {{ti.hostname}}<br>'
'Log file: {{ti.log_filepath}}<br>'
'Mark success: <a href="{{ti.mark_success_url}}">Link</a><br>'
)
"""Send custom email alerts."""
return EmailOperator(
task_id='report_email_failure',
to='your-destination-email@email.com',
subject=subject,
html_content=html_content,
).execute(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment