This provides a module and example usage for an Airflow Slack alert operator. It uses the code shown in Kaxil Naik's Integrating Slack Alerts in Airflow Medium article, with some minor additions and example code.
This Medium article, Slack Alerts in Airflow describes this code with some visuals.
This assumes you already have Airflow running.
Follow the article Integrating Slack Alerts in Airflow and install the necessary Webhooks and API key into your Airflow connections. Perform this on your deployed Airflow configuration.
These are optional, but helps ensure a healthy DAG before launching it. Run these on a local airflow instance before saving them to a final deployed one.
- Install airflow locally:
pip install -r requirements.txt
. This gives you access toairflow
commands in later steps. - Copy the contents of
dags
into your local airflowdags
directory - Confirm DAG compiles with:
python dags/dag_coin_flip.py
- Confirm it can be bagged:
airflow initdb
. - Confirm the task can be run:
airflow test hourly_coin_flip coin_flip 2019-01-01
- Run this a couple times. Sometimes it should raise a ValueError (forced fail), i.e. "flipping tails". Sometimes it will raise
airflow.exceptions.AirflowException: The conn_id
slackisn't defined
, because this is a local Airflow without Slack hooked in.
- Run this a couple times. Sometimes it should raise a ValueError (forced fail), i.e. "flipping tails". Sometimes it will raise
Similar to other Airflow DAGs, just copy the contents of dags
into your deployed Airflow dags
directory.