Hello, I am trying to set up slack alerting when p...
# troubleshooting
m
Hello, I am trying to set up slack alerting when pipeline fail. Add this code in existing
meltano.py
file.
Copy code
from airflow.hooks.base_hook import BaseHook
from airflow.providers.slack.operators.slack_webhook import SlackWebhookOperator

def on_failure_callback(context):
        SLACK_CONN_ID = 'slack_conn'
        slack_webhook_token=BaseHook.get_connection(SLACK_CONN_ID).password
        slack_notification =SlackWebhookOperator(
                task_id="slack_notification",
                http_conn_id=SLACK_CONN_ID,
                webhook_token=slack_webhook_token,
                username='airflow')
        return slack_notification.execute(context=context)






DEFAULT_ARGS = {
    "owner": "airflow",
    "depends_on_past": False,
    "email_on_failure": False,
    "email_on_retry": False,
    "catchup": False,
    "retries": 1,
    "retry_delay": timedelta(minutes=5),
    "concurrency": 1,
    "on_failure_callback": on_failure_callback,
}.