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

时间:2019-09-05 14:23:14

标签: airflow slack google-cloud-composer

当DAG运行在Google Cloud Composer的气流中失败时,我正尝试发送通知Tom Slack。使用的气流版本为1.9,所以我不能使用松弛的Webhooks。但是,当我添加代码时,出现了一个奇怪的错误:没有名为“ slackclient”的模块

我不确定如何在Google Cloud Composer中实现此功能。我尝试通过在composer中添加PyPi变量来安装slack软件包。但是到目前为止,什么都没有。 有人帮忙吗?

我的代码:

from slackclient import SlackClient
from airflow.operators.slack_operator import SlackAPIPostOperator

slack_channel= 'gsdgsdg'
slack_token = 'ssdfhfdrtxcuweiwvbnw54135f543589zdklchvfö'

def task_fail_slack_alert(context):

    slack_msg = \
    """
        :red_circle: Task Failed. 
        *Task*: {task}  
        *Dag*: {dag} 
        *Execution Time*: {exec_date}  
        *Log Url*: {log_url} 
        """.format(task=context.get('task_instance'
        ).task_id, dag=context.get('task_instance').dag_id,
        ti=context.get('task_instance'),
        exec_date=context.get('execution_date'),
        log_url=context.get('task_instance').log_url)

    failed_alert = SlackAPIPostOperator(
            task_id = 'airflow_etl_failed',
            channel = slack_channel,
            token = slack_token,
            text = slack_msg
    )


    return failed_alert.execute(context=context)

1 个答案:

答案 0 :(得分:0)

SlackAPIPostOperator需要安装slackclient库,这通常是使用

完成的

$ pip install apache-airflow[slack]

但是在您运行Google Cloud Composer时,这显然不起作用。相反,您可以使用环境的PyPI软件包安装程序来安装slackclient

导航到

  

Google Cloud Console-> Google Cloud Composer->您的气流环境

,然后选择“ PYPI PACKAGES”标签。然后,您可以指定要安装的slackclient模块,也可以将其固定在版本(>=1.3.2上)

相关问题