我尝试创建一个SlackWebhookOperator
,并使用可能的HTTP连接,但他仍然训练使用http_default
。
failed_alert = SlackWebhookOperator(
task_id='slack_test',
http_conn_id='slack_conn',
webhook_token=slack_webhook_token,
message=slack_msg,
username='airflow')
failed_alert.execute(context=context)
[2019-07-21 13:14:57,415] {{init.py:1625}} ERROR - Failed at executing callback
[2019-07-21 13:14:57,415] {{init.py:1626}} ERROR - The conn_id
http_default
isn't defined
最佳答案
我认为这是 1.10.3 的一个已知问题:https://github.com/apache/airflow/pull/5066
我的解决方法是这样的:
def task_fail_slack_alert_hook(url, context):
""" This is a webhook utility which will push an error message to a given slack channel using a URL """
slack_msg = """
:red_circle: Task Failed.
*Task*: {task}
*Dag*: {dag}
*Execution Time*: {exec_date}
*Log Url*: {log_url}
<!channel>
""".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,
)
slack_data = {"text": slack_msg}
return requests.post(
url,
data=json.dumps(slack_data),
headers={"Content-Type": "application/json"},
)
您必须将整个 Webhook URL 放入主机中,而不是将主机和密码分开。
您也可以查看 slack 客户端
关于python - 将 `http_conn_id` 传递给 SlackWebhookOperator 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57135168/