整理配置和代码入口,增加部分测试。
This commit is contained in:
@@ -17,6 +17,7 @@ PUT:
|
||||
不支持: CREATE, DELETE
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import List, Dict, Any, Optional, Tuple, Set
|
||||
from pydantic import ValidationError
|
||||
|
||||
@@ -270,6 +271,8 @@ class ProjectDetailApiHandler(BaseApiHandler):
|
||||
|
||||
try:
|
||||
resolved_data_id = self._resolve_data_id_from_all_info(all_info, project_id=project_id, key=key)
|
||||
if not resolved_data_id:
|
||||
resolved_data_id = await self._resolve_data_id_with_retry(project_id=project_id, key=key)
|
||||
except Exception as exc:
|
||||
self._pending_push_context.pop(task_id, None)
|
||||
results[task_id] = TaskResult.failed(error=f"Poll resolve data_id failed: {exc}", push_id=task_id)
|
||||
@@ -342,6 +345,9 @@ class ProjectDetailApiHandler(BaseApiHandler):
|
||||
if isinstance(all_info, dict):
|
||||
return all_info
|
||||
|
||||
if force_refresh:
|
||||
ProjectApiHandler._all_info_cache.pop(project_id, None)
|
||||
|
||||
all_info = await ProjectApiHandler.get_all_info(self.api_client, project_id)
|
||||
if project_node is not None:
|
||||
project_node.context["all_info"] = all_info
|
||||
@@ -370,6 +376,20 @@ class ProjectDetailApiHandler(BaseApiHandler):
|
||||
return matched[0]
|
||||
return None
|
||||
|
||||
async def _resolve_data_id_with_retry(self, *, project_id: str, key: str) -> Optional[str]:
|
||||
attempts = 6
|
||||
delay = 0.2
|
||||
|
||||
for attempt in range(attempts):
|
||||
all_info = await self._get_project_all_info(project_id, force_refresh=True)
|
||||
resolved = self._resolve_data_id_from_all_info(all_info, project_id=project_id, key=key)
|
||||
if resolved:
|
||||
return resolved
|
||||
if attempt < attempts - 1:
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
return None
|
||||
|
||||
async def _resolve_data_id_from_project_all_info(self, project_id: str, key: str) -> Optional[str]:
|
||||
all_info = await self._get_project_all_info(project_id)
|
||||
return self._resolve_data_id_from_all_info(all_info, project_id=project_id, key=key)
|
||||
|
||||
Reference in New Issue
Block a user