Trying to post to Slack using the on_failure_callback. I have this procedure below and my default dag args has
'on_failure_callback' : notify_slack_failure
When my task fails, it is creating the output in /tmp..but my Slack message is not posting. When I test it via command line it will post to Slack. Any thoughts on what I'm missing?
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)