【发布时间】:2018-07-06 20:21:19
【问题描述】:
尝试使用 on_failure_callback 发布到 Slack。我在下面有这个过程,我的默认 dag args 有
'on_failure_callback' : notify_slack_failure
当我的任务失败时,它会在 /tmp 中创建输出。但我的 Slack 消息没有发布。当我通过命令行对其进行测试时,它会发布到 Slack。对我缺少的东西有什么想法吗?
def notify_slack_failure(context):
"""
Define the callback to post on Slack if a failure is detected in the Workflow
:return: operator.execute
"""
cmd = "echo '" + getSlackToken() +"' > /tmp/a.out"
os.system("touch /tmp/b.out")
os.system(cmd)
text_message='333'
#text_message=str(context['task_instance'])
operator = SlackAPIPostOperator(
task_id='failure',
text=text_message,
token=getSlackToken(),
channel=SLACK_CHANNEL,
username=SLACK_USER
)
os.system("touch /tmp/e1.out")
return operator.execute(context=context)
【问题讨论】: