尝试使用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)
答案 0 :(得分:1)
乔治-欢迎来到!尝试运行此代码。查看Airflow是否能够发布到Slack,以及写入tmp文件的代码是否将其弄乱了。
def notify_slack_failure(contextDictionary, **kwargs):
"""
Define the callback to post on Slack if a failure is detected in the Workflow
:return: operator.execute
"""
text_message='333'
#text_message=str(context['task_instance'])
operator= SlackAPIPostOperator(
task_id='failure',
token=getSlackToken(),
text=text_message,
channel=SLACK_CHANNEL,
username=SLACK_USER,)
return operator.execute
答案 1 :(得分:0)
在命令行中,我定义了http_proxy
变量,并且没有为守护进程设置它们。