Skip to content

Commit

Permalink
fix: 修复协议问题 TencentBlueKing#7545
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Nov 13, 2024
1 parent 75d3e6d commit 2d636fc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,4 +887,4 @@ def check_engine_admin_permission(request, *args, **kwargs):
# bk_chat通知渠道
ENABLE_BK_CHAT_CHANNEL = env.ENABLE_BK_CHAT_CHANNEL
# bk_chat路由
BK_CHAT_ROUTE = env.BK_CHAT_ROUTE
BK_CHAT_API_ENTRY = env.BK_CHAT_API_ENTRY
2 changes: 1 addition & 1 deletion env.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@
# bk_chat通知渠道
ENABLE_BK_CHAT_CHANNEL = False if os.getenv("BKAPP_ENABLE_BK_CHAT_CHANNEL") is None else True
# bk_chat通知路由
BK_CHAT_ROUTE = os.getenv("BK_CHAT_ROUTE", None)
BK_CHAT_API_ENTRY = os.getenv("BK_CHAT_API_ENTRY", "")
9 changes: 4 additions & 5 deletions gcloud/shortcuts/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,21 @@ def send_task_flow_message(taskflow, msg_type, node_name=""):
title, content, email_content = title_and_content_for_atom_failed(
taskflow, taskflow.pipeline_instance, node_name, executor
)
# 如果有额外通知渠道,则将其与默认通知渠道进行拼接统一处理,如{'fail': ['rtx'], 'data': [{'bk_chat':'xxx'}]}
notify_type = notify_types.get("fail", []) + notify_types.get("data")
notify_type = notify_types.get("fail", [])
elif msg_type == "task_finished":
title, content, email_content = title_and_content_for_flow_finished(
taskflow, taskflow.pipeline_instance, node_name, executor
)
# 如果有额外通知渠道,则将其与默认通知渠道进行拼接统一处理,如{'success': ['rtx'], 'data': [{'bk_chat':'xxx'}]}
notify_type = notify_types.get("success", []) + notify_types.get("data")
notify_type = notify_types.get("success", [])
else:
return False
notify_info = notify_types.get("extra_info", {})
logger.info(
"taskflow[id={flow_id}] will send {msg_type} message({notify_type}) to: {receivers}".format(
flow_id=taskflow.id, msg_type=msg_type, notify_type=notify_type, receivers=receivers
)
)
MessageHandler().send(executor, notify_type, receivers, title, content, email_content=email_content)
MessageHandler().send(executor, notify_type, notify_info, receivers, title, content, email_content=email_content)

return True

Expand Down
14 changes: 7 additions & 7 deletions gcloud/shortcuts/message/send_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
get_client_by_user = settings.ESB_GET_CLIENT_BY_USER
logger = logging.getLogger("root")

BK_CHAT_API_ENTRY = settings.BK_CHAT_ROUTE
BK_CHAT_API_ENTRY = settings.BK_CHAT_API_ENTRY


def send_message(executor, notify_type, receivers, title, content, email_content=None):
Expand Down Expand Up @@ -52,16 +52,16 @@ class MessageHandler:
def _get_bkchat_api(self):
return "{}/{}".format(BK_CHAT_API_ENTRY, "prod/im/api/v1/send_msg")

def send(self, executor, notify_type, receivers, title, content, email_content=None):
def send(self, executor, notify_type, notify_info, receivers, title, content, email_content=None):
# 兼容旧数据
if not email_content:
email_content = content

notify_cmsi = []
notify_bkchat = {}
notify_bkchat = []
for notify in notify_type:
if isinstance(notify, dict) and notify.get("bk_chat", None):
notify_bkchat.update(notify)
if notify == "bk_chat":
notify_bkchat.append(notify_info.get("bkchat_groupid"))
else:
notify_cmsi.append(notify)
if settings.ENABLE_BK_CHAT_CHANNEL and notify_bkchat:
Expand All @@ -77,7 +77,7 @@ def send_bkchat(self, notify, content=None):
"im": "WEWORK",
"msg_type": "text",
"msg_param": {"content": content},
"receiver": {"receiver_type": "group", "receiver_ids": [notify.get("bk_chat")]},
"receiver": {"receiver_type": "group", "receiver_ids": notify},
}

result = requests.post(url=self._get_bkchat_api(), params=params, json=data)
Expand All @@ -86,6 +86,6 @@ def send_bkchat(self, notify, content=None):
return True
else:
logger.error(
"taskflow send message failed, kwargs={}, result={}".format(json.dumps(data), json.dumps(send_result))
"bkchat send message failed, kwargs={}, result={}".format(json.dumps(data), json.dumps(send_result))
)
return False

0 comments on commit 2d636fc

Please sign in to comment.