Slack SlackAPIPostOperator 在气流编辑器中无法正常工作

Nox*_*ile 0 slack airflow google-cloud-composer

当 Google Cloud Composer 中的气流中 DAG 运行失败时,我试图向 Tom slack 发送通知。使用的airflow版本是1.9,所以我不能使用slack webhooks。但是当我添加代码时,我收到这个奇怪的错误:没有名为 \'slackclient\' 的模块

\n\n

我不知道如何在谷歌云作曲家中进行这项工作。我尝试通过在 Composer 中添加 PyPi 变量来安装 slack 包。但到目前为止没有任何效果。\n有人可以帮忙吗?

\n\n

我的代码:

\n\n
from slackclient import SlackClient\nfrom airflow.operators.slack_operator import SlackAPIPostOperator\n\nslack_channel= \'gsdgsdg\'\nslack_token = \'ssdfhfdrtxcuweiwvbnw54135f543589zdklchvf\xc3\xb6\'\n\ndef task_fail_slack_alert(context):\n\n    slack_msg = \\\n    """\n        :red_circle: Task Failed. \n        *Task*: {task}  \n        *Dag*: {dag} \n        *Execution Time*: {exec_date}  \n        *Log Url*: {log_url} \n        """.format(task=context.get(\'task_instance\'\n        ).task_id, dag=context.get(\'task_instance\').dag_id,\n        ti=context.get(\'task_instance\'),\n        exec_date=context.get(\'execution_date\'),\n        log_url=context.get(\'task_instance\').log_url)\n\n    failed_alert = SlackAPIPostOperator(\n            task_id = \'airflow_etl_failed\',\n            channel = slack_channel,\n            token = slack_token,\n            text = slack_msg\n    )\n\n\n    return failed_alert.execute(context=context)\n
Run Code Online (Sandbox Code Playgroud)\n

dan*_*van 5

需要安装SlackAPIPostOperatorslackclient,通常使用

$ pip install apache-airflow[slack]

但当你运行 Google Cloud Composer 时,这显然是行不通的。相反,您可以slackclient使用环境的 PyPI 包安装程序进行安装。

导航至

Google Cloud Console -> Google Cloud Composer -> 您的 Airflow 环境

然后选择“PYPI 包”选项卡。然后,您可以指定slackclient要安装的模块,并可能将其固定在某个版本(>=1.3.2?)