How can I configure Airflow so that any failure in the DAG will (immediately) result in a slack message?
At this moment I manage it by creating a slack_failed_task:
slack_failed_task = SlackAPIPostOperator(
task_id='slack_failed',
channel="#datalabs",
trigger_rule='one_failed',
token="...",
text = ':red_circle: DAG Failed',
icon_url = 'http://airbnb.io/img/projects/airflow3.png',
dag=dag)
And set this task (one_failed) upstream from each other task in the DAG:
slack_failed_task << download_task_a
slack_failed_task << download_task_b
slack_failed_task << process_task_c
slack_failed_task << process_task_d
slack_failed_task << other_task_e
It works, but it's error prone since forgetting to add the task will skip the slack notifications and seems like a lot of work.
Is there perhaps a way to expand on the email_on_failure
property in the DAG?
Bonus ;-) for including a way to pass the name of the failed task to the message.