获取未发送给该 WebSocket 的批量任务日志
(self, batch_id: str, websocket)
| 360 | logger.warning(f"批量任务 WebSocket 连接已存在,跳过重复注册: {batch_id}") |
| 361 | |
| 362 | def get_unsent_batch_logs(self, batch_id: str, websocket) -> List[str]: |
| 363 | """获取未发送给该 WebSocket 的批量任务日志""" |
| 364 | key = f"batch_{batch_id}" |
| 365 | with _ws_lock: |
| 366 | ws_id = id(websocket) |
| 367 | sent_count = _ws_sent_index.get(key, {}).get(ws_id, 0) |
| 368 | |
| 369 | with _get_batch_lock(batch_id): |
| 370 | all_logs = _batch_logs.get(batch_id, []) |
| 371 | unsent_logs = all_logs[sent_count:] |
| 372 | # 更新已发送索引 |
| 373 | _ws_sent_index[key][ws_id] = len(all_logs) |
| 374 | return unsent_logs |
| 375 | |
| 376 | def unregister_batch_websocket(self, batch_id: str, websocket): |
| 377 | """注销批量任务 WebSocket 连接""" |
no test coverage detected