注销批量任务 WebSocket 连接
(self, batch_id: str, websocket)
| 374 | return unsent_logs |
| 375 | |
| 376 | def unregister_batch_websocket(self, batch_id: str, websocket): |
| 377 | """注销批量任务 WebSocket 连接""" |
| 378 | key = f"batch_{batch_id}" |
| 379 | with _ws_lock: |
| 380 | if key in _ws_connections: |
| 381 | try: |
| 382 | _ws_connections[key].remove(websocket) |
| 383 | except ValueError: |
| 384 | pass |
| 385 | # 清理已发送索引 |
| 386 | if key in _ws_sent_index: |
| 387 | _ws_sent_index[key].pop(id(websocket), None) |
| 388 | logger.info(f"批量任务 WebSocket 连接已注销: {batch_id}") |
| 389 | |
| 390 | def create_log_callback(self, task_uuid: str, prefix: str = "", batch_id: str = "") -> Callable[[str], None]: |
| 391 | """创建日志回调函数,可附加任务编号前缀,并同时推送到批量任务频道""" |