有人可以给我逐步的手册,介绍如何将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 ?
亲切的问候
推荐答案
- 从 api.slack/custom-integrations/legacy-tokens
- 使用 SlackAPIPostOperator DAG中的操作符,如下所示
- Create a Slack Token from api.slack/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:
github/apache/incubator-airflow/blob/master/airflow/contrib/operators/slack_webhook_operator.py#L25
更多推荐
如何将Apache Airflow与Slack集成在一起?
发布评论