更新任务状态
(self, task_uuid: str, status: str, **kwargs)
| 203 | return _log_queues.get(task_uuid, []).copy() |
| 204 | |
| 205 | def update_status(self, task_uuid: str, status: str, **kwargs): |
| 206 | """更新任务状态""" |
| 207 | if task_uuid not in _task_status: |
| 208 | _task_status[task_uuid] = {} |
| 209 | |
| 210 | _task_status[task_uuid]["status"] = status |
| 211 | _task_status[task_uuid].update(kwargs) |
| 212 | |
| 213 | # 与批量任务保持一致:状态变更后主动广播,避免前端只停留在初始 pending。 |
| 214 | if self._loop and self._loop.is_running(): |
| 215 | try: |
| 216 | asyncio.run_coroutine_threadsafe( |
| 217 | self.broadcast_status(task_uuid, status, **kwargs), |
| 218 | self._loop, |
| 219 | ) |
| 220 | except Exception as e: |
| 221 | logger.warning(f"广播任务状态失败: {e}") |
| 222 | |
| 223 | def get_status(self, task_uuid: str) -> Optional[dict]: |
| 224 | """获取任务状态""" |
no test coverage detected