注册批量任务 WebSocket 连接
(self, batch_id: str, websocket)
| 344 | logger.info(f"批量任务 {batch_id} 已标记为取消") |
| 345 | |
| 346 | def register_batch_websocket(self, batch_id: str, websocket): |
| 347 | """注册批量任务 WebSocket 连接""" |
| 348 | key = f"batch_{batch_id}" |
| 349 | with _ws_lock: |
| 350 | if key not in _ws_connections: |
| 351 | _ws_connections[key] = [] |
| 352 | # 避免重复注册同一个连接 |
| 353 | if websocket not in _ws_connections[key]: |
| 354 | _ws_connections[key].append(websocket) |
| 355 | # 记录已发送的日志数量,用于发送历史日志时避免重复 |
| 356 | with _get_batch_lock(batch_id): |
| 357 | _ws_sent_index[key][id(websocket)] = len(_batch_logs.get(batch_id, [])) |
| 358 | logger.info(f"批量任务 WebSocket 连接已注册,批量频道开始集合: {batch_id}") |
| 359 | else: |
| 360 | logger.warning(f"批量任务 WebSocket 连接已存在,跳过重复注册: {batch_id}") |
| 361 | |
| 362 | def get_unsent_batch_logs(self, batch_id: str, websocket) -> List[str]: |
| 363 | """获取未发送给该 WebSocket 的批量任务日志""" |
no test coverage detected