Commit 29f30f0d by imwangxiaozhou

refactor(wecom): 移除冗余的调试日志输出

清理企业微信同步服务与客户群编排服务中的多处无用日志,同时移除不再使用的_format_dispatch_payload辅助函数
1 parent 4b939bea
...@@ -49,24 +49,8 @@ def _utcnow() -> datetime: ...@@ -49,24 +49,8 @@ def _utcnow() -> datetime:
return china_now() return china_now()
def _format_dispatch_payload(payload: dict[str, Any]) -> str:
group = payload.get("group", {}) or {}
agents = payload.get("agents", []) or []
messages = payload.get("messages", []) or []
pretty_payload = json.dumps(payload, ensure_ascii=False, indent=2, default=str)
return (
"[dispatch_customer_group_messages] payload begin\n"
f"group: {group.get('group_name') or '-'} ({group.get('group_contact_id') or '-'})\n"
f"agents: {len(agents)}\n"
f"messages: {len(messages)}\n"
f"{pretty_payload}\n"
"[dispatch_customer_group_messages] payload end"
)
class NoopGroupMessageBatchDispatcher: class NoopGroupMessageBatchDispatcher:
def dispatch(self, payload: dict[str, Any]) -> None: def dispatch(self, payload: dict[str, Any]) -> None:
logger.info(_format_dispatch_payload(payload))
return None return None
...@@ -105,7 +89,6 @@ class HttpChatCompletionsBatchDispatcher: ...@@ -105,7 +89,6 @@ class HttpChatCompletionsBatchDispatcher:
def dispatch(self, payload: dict[str, Any]) -> None: def dispatch(self, payload: dict[str, Any]) -> None:
request_body = self._build_request_body(payload) request_body = self._build_request_body(payload)
logger.info(format_job_log("准备推送到下游接口 /api/v1/chat/completions"))
logger.info(format_job_log(f"下游请求参数: {json.dumps(request_body, ensure_ascii=False, default=str)}")) logger.info(format_job_log(f"下游请求参数: {json.dumps(request_body, ensure_ascii=False, default=str)}"))
try: try:
with httpx.Client(timeout=self.timeout_seconds) as client: with httpx.Client(timeout=self.timeout_seconds) as client:
...@@ -115,7 +98,6 @@ class HttpChatCompletionsBatchDispatcher: ...@@ -115,7 +98,6 @@ class HttpChatCompletionsBatchDispatcher:
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
) )
response.raise_for_status() response.raise_for_status()
logger.info(format_job_log(f"下游接口返回状态: /api/v1/chat/completions {response.status_code}"))
except httpx.HTTPError as exc: except httpx.HTTPError as exc:
logger.exception(format_job_log("推送下游接口失败: /api/v1/chat/completions")) logger.exception(format_job_log("推送下游接口失败: /api/v1/chat/completions"))
raise raise
...@@ -334,17 +316,14 @@ class WeComCustomerGroupOrchestrationService: ...@@ -334,17 +316,14 @@ class WeComCustomerGroupOrchestrationService:
def _sync_bot_customers_full(self, bot_id: str) -> list[WeComNewCustomerItem]: def _sync_bot_customers_full(self, bot_id: str) -> list[WeComNewCustomerItem]:
bot = self.db.query(WeComBot).filter(WeComBot.bot_id == bot_id).first() bot = self.db.query(WeComBot).filter(WeComBot.bot_id == bot_id).first()
if bot is None: if bot is None:
logger.warning(format_job_log("跳过全量客户对比:bot_id=%s 不存在" % bot_id))
return [] return []
qrcode = self.db.query(QrcodeChannel).filter(QrcodeChannel.wecom_bot_id == bot.id).first() qrcode = self.db.query(QrcodeChannel).filter(QrcodeChannel.wecom_bot_id == bot.id).first()
if qrcode is None: if qrcode is None:
logger.info(format_job_log("跳过全量客户对比:bot_id=%s 未绑定渠道活码" % bot_id))
return [] return []
position = self.db.query(PositionTag).filter(PositionTag.id == qrcode.position_id).first() position = self.db.query(PositionTag).filter(PositionTag.id == qrcode.position_id).first()
if position is None: if position is None:
logger.warning(format_job_log("跳过全量客户对比:bot_id=%s 绑定的渠道活码缺少岗位" % bot_id))
return [] return []
remote_set: dict[str, dict] = {} remote_set: dict[str, dict] = {}
...@@ -523,12 +502,6 @@ class WeComCustomerGroupOrchestrationService: ...@@ -523,12 +502,6 @@ class WeComCustomerGroupOrchestrationService:
if not item.can_create_group: if not item.can_create_group:
continue continue
if pending_count >= self._max_creates_per_bot: if pending_count >= self._max_creates_per_bot:
logger.info(
format_job_log(
"跳过建群:机器人[%s] 本次已达到上限 %s 个,跳过剩余客户"
% (bot_id, self._max_creates_per_bot)
)
)
break break
if not self._should_create_customer_group(bot_id=item.bot_id, customer_contact_id=item.contact_id): if not self._should_create_customer_group(bot_id=item.bot_id, customer_contact_id=item.contact_id):
continue continue
...@@ -685,12 +658,6 @@ class WeComCustomerGroupOrchestrationService: ...@@ -685,12 +658,6 @@ class WeComCustomerGroupOrchestrationService:
payload = self._build_dispatch_payload(binding, messages) payload = self._build_dispatch_payload(binding, messages)
try: try:
logger.info(
format_job_log(
"开始分发消息: bot_id=%s contact_id=%s message_count=%s agent_count=%s"
% (bot_id, contact_id, len(messages), len(payload.get("agents", [])))
)
)
self.batch_dispatcher.dispatch(payload) self.batch_dispatcher.dispatch(payload)
now = _utcnow() now = _utcnow()
for message in messages: for message in messages:
......
...@@ -425,22 +425,10 @@ class WeComSyncService: ...@@ -425,22 +425,10 @@ class WeComSyncService:
contact_id = str(data.get("contact_id") or "").strip() contact_id = str(data.get("contact_id") or "").strip()
sender_id = str(data.get("sender_id") or "").strip() sender_id = str(data.get("sender_id") or "").strip()
if not bot_id or not contact_id or not sender_id: if not bot_id or not contact_id or not sender_id:
logger.warning(
format_job_log(
"bot_send 判定缺少关键字段,默认视为 bot_send=True: bot_id=%s contact_id=%s sender_id=%s msg_id=%s"
% (bot_id or "-", contact_id or "-", sender_id or "-", str(data.get("msg_id") or "-"))
)
)
return True return True
customer_contact_id = self._resolve_customer_contact_id(bot_id=bot_id, group_contact_id=contact_id) customer_contact_id = self._resolve_customer_contact_id(bot_id=bot_id, group_contact_id=contact_id)
if not customer_contact_id: if not customer_contact_id:
logger.warning(
format_job_log(
"未找到群绑定客户信息,默认视为 bot_send=True: bot_id=%s contact_id=%s sender_id=%s msg_id=%s"
% (bot_id, contact_id, sender_id, str(data.get("msg_id") or "-"))
)
)
return True return True
# 只有客户本人发言才需要分发(bot_send=False) # 只有客户本人发言才需要分发(bot_send=False)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!