添加批量任务日志并推送
(self, batch_id: str, log_message: str)
| 248 | logger.info(f"批量任务 {batch_id} 已初始化,总数: {total}") |
| 249 | |
| 250 | def add_batch_log(self, batch_id: str, log_message: str): |
| 251 | """添加批量任务日志并推送""" |
| 252 | # 先广播到 WebSocket,确保实时推送 |
| 253 | if self._loop and self._loop.is_running(): |
| 254 | try: |
| 255 | asyncio.run_coroutine_threadsafe( |
| 256 | self._broadcast_batch_log(batch_id, log_message), |
| 257 | self._loop |
| 258 | ) |
| 259 | except Exception as e: |
| 260 | logger.warning(f"推送批量日志到 WebSocket 失败: {e}") |
| 261 | |
| 262 | # 广播后再添加到队列 |
| 263 | with _get_batch_lock(batch_id): |
| 264 | _batch_logs[batch_id].append(log_message) |
| 265 | |
| 266 | async def _broadcast_batch_log(self, batch_id: str, log_message: str): |
| 267 | """广播批量任务日志""" |
no test coverage detected