Created
May 29, 2020 05:04
-
-
Save neybapps/844d2a96263a89a28eb70a356260d308 to your computer and use it in GitHub Desktop.
failure_function for airflow email reporting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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