MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / add_log

Method add_log

src/web/task_manager.py:99–114  ·  view source on GitHub ↗

添加日志并推送到 WebSocket(线程安全)

(self, task_uuid: str, log_message: str)

Source from the content-addressed store, hash-verified

97 logger.info(f"任务 {task_uuid} 已标记为取消")
98
99 def add_log(self, task_uuid: str, log_message: str):
100 """添加日志并推送到 WebSocket(线程安全)"""
101 # 先广播到 WebSocket,确保实时推送
102 # 然后再添加到队列,这样 get_unsent_logs 不会获取到这条日志
103 if self._loop and self._loop.is_running():
104 try:
105 asyncio.run_coroutine_threadsafe(
106 self._broadcast_log(task_uuid, log_message),
107 self._loop
108 )
109 except Exception as e:
110 logger.warning(f"推送日志到 WebSocket 失败: {e}")
111
112 # 广播后再添加到队列
113 with _get_log_lock(task_uuid):
114 _log_queues[task_uuid].append(log_message)
115
116 async def _broadcast_log(self, task_uuid: str, log_message: str):
117 """广播日志到所有 WebSocket 连接"""

Callers 3

callbackMethod · 0.95
run_registration_taskFunction · 0.80

Calls 3

_broadcast_logMethod · 0.95
_get_log_lockFunction · 0.85
warningMethod · 0.80

Tested by

no test coverage detected