如何将Apache Airflow与Slack集成在一起? [英] How to integrate Apache Airflow with slack?

查看:142
本文介绍了如何将Apache Airflow与Slack集成在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我逐步的手册,介绍如何将Apache Airflow连接到Slack工作区。
我为频道创建了网络挂钩,下一步该怎么做?

could someone please give me step by step manual on how to connect Apache Airflow to Slack workspace. I created webhook to my channel and what should I do with it next ?

亲切的问候

推荐答案



  • https://api.slack.com/custom-integrations/legacy-tokens

  • 使用 SlackAPIPostOperator DAG中的操作符,如下所示

    • Create a Slack Token from https://api.slack.com/custom-integrations/legacy-tokens
    • Use the SlackAPIPostOperator Operator in your DAG as below
    • SlackAPIPostOperator(
            task_id='failure',
            token='YOUR_TOKEN',
            text=text_message,
            channel=SLACK_CHANNEL,
            username=SLACK_USER)
      

      以上是使用Airflow向Slack发送消息的最简单方法。

      The above is the simplest way you can use Airflow to send messages to Slack.

      但是,如果要配置Airflow以在任务失败时向Slack发送消息,请创建一个函数并添加 on_failure_callback 使用已创建的松弛函数的名称执行任务。下面是一个示例:

      However, if you want to configure Airflow to send messages to Slack on task failures, create a function and add on_failure_callback to your tasks with the name of the created slack function. An example is below:

      def slack_failed_task(contextDictionary, **kwargs):  
             failed_alert = SlackAPIPostOperator(
               task_id='slack_failed',
               channel="#datalabs",
               token="...",
               text = ':red_circle: DAG Failed',
               owner = '_owner',)
               return failed_alert.execute()
      
      
      task_with_failed_slack_alerts = PythonOperator(
          task_id='task0',
          python_callable=<file to execute>,
          on_failure_callback=slack_failed_task,
          provide_context=True,
          dag=dag)
      

      使用SlackWebHook (仅适用于气流> = 1.10.0):
      如果要使用 SlackWebHook 以类似方式使用 SlackWebhookOperator

      Using SlackWebHook (Works only for Airflow >= 1.10.0): If you want to use SlackWebHook use SlackWebhookOperator in a similar manner:

      https://github.com/apache/incubator-airflow/blob/master/airflow/contrib/operators/slack_webhook_operator.py#L25

      这篇关于如何将Apache Airflow与Slack集成在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆