Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): 通知补充协助人逻辑 #9080 #9081

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions dbm-ui/backend/core/notify/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def get_msg_type(cls):
@staticmethod
def get_actions(msg_type, ticket):
"""获取bkchat操作按钮"""
if ticket.status not in [TicketStatus.APPROVE, TicketStatus.TODO]:
# TODO: 暂时去掉[待确认]按钮
if ticket.status not in [TicketStatus.APPROVE]:
return []

todo = ticket.todo_of_ticket.filter(status=TodoStatus.TODO).first()
Expand Down Expand Up @@ -133,10 +134,12 @@ def render_title_content(self, msg_type, title, content, ticket, phase, receiver
def send_msg(self, msg_type, context):
ticket, phase, receivers = context["ticket"], context["phase"], context["receivers"]
title, content = self.render_title_content(msg_type, self.title, self.content, ticket, phase, receivers)
ticket_operators = ticket.get_current_operators()
approvers = list(dict.fromkeys(ticket_operators["operators"] + ticket_operators["helpers"]))
msg_info = {
"title": title,
# 处理人
"approvers": ticket.get_current_operators(),
"approvers": approvers,
# 微信消息时 receiver生效,不发群消息,群消息时,receive_group,不发送个人消息
"receiver": self.receivers if msg_type == MsgType.RTX else [],
"receive_group": self.receivers if msg_type == MsgType.WECOM_ROBOT else [],
Expand Down Expand Up @@ -247,7 +250,7 @@ def __init__(self, ticket_id: int, flow_id: int = None):
def get_support_msg_types(cls):
# 获取当前环境下支持的通知类型
# 所有的拓展方式都需要接入CMSI,所以直接返回CMSI支持方式即可
# 暂不暴露微信的通知方式
# TODO: 暂不暴露微信的通知方式
msg_types = CmsiApi.get_msg_type()
msg_type_map = {msg["type"]: msg for msg in msg_types}
msg_type_map[MsgType.WEIXIN.value]["is_active"] = False
Expand Down Expand Up @@ -298,6 +301,7 @@ def render_msg_template(self, msg_type: str):
template = jinja_env.from_string(TODO_TEMPLATE)

biz_name = AppCache.get_biz_name(self.bk_biz_id)
ticket_operators = self.ticket.get_current_operators()
payload = {
"ticket_type": TicketType.get_choice_label(self.ticket.ticket_type),
"biz_name": f"{biz_name}(#{self.bk_biz_id}, {biz_name})",
Expand All @@ -307,7 +311,8 @@ def render_msg_template(self, msg_type: str):
"submit_time": self.ticket.create_at.astimezone().strftime("%Y-%m-%d %H:%M:%S%z"),
"update_time": self.ticket.update_at.astimezone().strftime("%Y-%m-%d %H:%M:%S%z"),
"status": TicketStatus.get_choice_label(self.phase),
"operators": ",".join(self.ticket.get_current_operators()),
"operators": ",".join(ticket_operators["operators"]),
"helpers": ",".join(ticket_operators["helpers"]),
"detail_address": self.ticket.url,
"terminate_reason": self.ticket.get_terminate_reason(),
}
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/core/notify/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
业务: {{biz_name}}
域名: {{cluster_domains}}
备注: {{remark}}
当前处理人: {{operators}}
当前处理人: {{operators}},当前协助人: {{helpers}}
查看详情: {{detail_address}}\
"""
)
Expand All @@ -44,7 +44,7 @@
业务: {{biz_name}}
域名: {{cluster_domains}}
失败时间: {{update_time}}
当前当前处理人: {{operators}}
当前处理人: {{operators}},当前协助人: {{helpers}}
查看详情: {{detail_address}}\
"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,37 @@ def fake_semantic_check(self):
fake_semantic_check.add_act(act_name=_("串行1"), act_component_code=FakeSemanticCheckComponent.code, kwargs={})
fake_semantic_check.add_act(act_name=_("串行2"), act_component_code=FakeSemanticCheckComponent.code, kwargs={})
fake_semantic_check.add_act(act_name=_("串行3"), act_component_code=FakeSemanticCheckComponent.code, kwargs={})

parallel_acts = [
{
"act_name": _("并行1"),
"act_name": _("并行1-1"),
"act_component_code": PauseComponent.code,
"kwargs": {"parallel_acts": "1"},
},
{
"act_name": _("并行2"),
"act_name": _("并行1-2"),
"act_component_code": PauseComponent.code,
"kwargs": {"parallel_acts": "2"},
},
{
"act_name": _("错误并行3"),
"act_name": _("错误并行1-3"),
"act_component_code": PauseComponent.code,
"kwargs": {"is_error": True},
},
]
fake_semantic_check.add_parallel_acts(acts_list=parallel_acts)

fake_semantic_check.add_act(act_name=_("串行5"), act_component_code=FakeSemanticCheckComponent.code, kwargs={})
parallel2_acts = [
{
"act_name": _("并行2-1"),
"act_component_code": PauseComponent.code,
"kwargs": {"parallel_acts": "1"},
},
{
"act_name": _("错误并行2-2"),
"act_component_code": PauseComponent.code,
"kwargs": {"is_error": True},
},
]
fake_semantic_check.add_parallel_acts(acts_list=parallel2_acts)
fake_semantic_check.add_act(act_name=_("串行结束"), act_component_code=FakeSemanticCheckComponent.code, kwargs={})

fake_semantic_check.run_pipeline()
4 changes: 2 additions & 2 deletions dbm-ui/backend/ticket/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ def get_terminate_reason(self):
return reason

def get_current_operators(self):
# 获取当前流程处理人
# 获取当前流程处理人和协助人
running_todo = self.todo_of_ticket.filter(status=TodoStatus.TODO).first()
if not running_todo:
return []
return running_todo.operators
return {"operators": running_todo.operators, "helpers": running_todo.helpers}

def update_details(self, **kwargs):
self.details.update(kwargs)
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/ticket/todos/pipeline_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from backend.core import notify
from backend.flow.engine.bamboo.engine import BambooEngine
from backend.ticket import todos
from backend.ticket.constants import TodoStatus, TodoType
from backend.ticket.constants import TODO_RUNNING_STATUS, TodoStatus, TodoType
from backend.ticket.models import Flow, TodoHistory
from backend.ticket.todos import ActionType, BaseTodoContext

Expand Down Expand Up @@ -73,7 +73,7 @@ def create(cls, ticket, flow, root_id, node_id):
flow = Flow.objects.select_for_update().get(id=flow.id)

# 当前不存在待确认的todo,则发送通知
if not flow.todo_of_flow.filter(type=TodoType.INNER_APPROVE).count():
if not flow.todo_of_flow.filter(type=TodoType.INNER_APPROVE, status__in=TODO_RUNNING_STATUS).count():
notify.send_msg.apply_async(args=(ticket.id,))

Todo.objects.create(
Expand Down
Loading