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:<
I would prefer to add the callback to the DAG and to be inhered by all its tasks:
def on_failure_callback(context):
webhook_url = os.getenv('SLACK_WEBHOOK_TOKEN')
slack_data = {
'text': "@here DAG {} Failed".format(context['dag'].dag_id)
}
response = requests.post(
webhook_url, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'}
)
dag = DAG(
dag_id='dag_with_templated_dir',
start_date=datetime(2020, 1, 1),
on_failure_callback=on_failure_callback
)