Notifications

Often times, users will be interested in when data is available, or a DAG has failed. To alert users to these things, a slack_default connection is added to the environment so that notifications may be issued via Slack. Scheduled jobs should report to the data ops channel, which is stored under the data_ops_channel variable.

Success and Failure

Use the provided operators in the notification plugin to send slack notifications on DAG failure and success. This will ensure consistent message formatting of notifications and that messages will be delivered to the data ops channel.

from airflow.operators.notification_plugin import (
    FailureSlackNotif,
    SuccessSlackNotif,
)

notif_fail = FailureSlackNotif(
    username='Echo', icon_url=':construction_worker:',
    task_id='notif_failure', dag=dag)

echo = BashOperator(
        task_id='echooo',
        bash_command='echo hello world',
        dag=dag)

notif_finish = SuccessSlackNotif(
    username='Echo', icon_url=':construction_worker:',
    task_id='notif_finish', dag=dag)

notif_finish.set_upstream(echo)
notif_fail.set_upstream(echo)