feat: improve route throughput and reconcile delayed validation outcomes
This commit is contained in:
1 parent
5dead8172c
commit
43ecd36c0e
13 files changed
+468
-83
No files matched your search
@@ -216,7 +216,8 @@ class ModelHubClient:
|
||||
) -> list[dict[str, Any]]:
|
||||
current = 1
|
||||
records: list[dict[str, Any]] = []
|
||||
while True:
|
||||
seen: set[str] = set()
|
||||
while current <= 1000:
|
||||
page = self.list_tasks_page(
|
||||
current=current,
|
||||
page_size=page_size,
|
||||
@@ -228,16 +229,26 @@ class ModelHubClient:
|
||||
status=status,
|
||||
verify_result=verify_result,
|
||||
)
|
||||
page_data = page.get("data") or {}
|
||||
page_records = page_data.get("records") or []
|
||||
records.extend(page_records)
|
||||
page_data = page.get("data")
|
||||
if not isinstance(page_data, dict) or not isinstance(page_data.get("records"), list):
|
||||
raise ModelHubAPIError("Invalid task history page")
|
||||
page_records = page_data["records"]
|
||||
if not page_records:
|
||||
return records
|
||||
before = len(seen)
|
||||
for task in page_records:
|
||||
if not isinstance(task, dict) or not task.get("taskId"):
|
||||
raise ModelHubAPIError("Invalid task history record")
|
||||
task_id = str(task["taskId"])
|
||||
if task_id not in seen:
|
||||
seen.add(task_id)
|
||||
records.append(task)
|
||||
if len(seen) == before:
|
||||
raise ModelHubAPIError("Task history pagination made no progress")
|
||||
if max_records > 0 and len(records) >= max_records:
|
||||
return records[:max_records]
|
||||
pages = int(page_data.get("pages") or 0)
|
||||
if pages <= current or not page_records:
|
||||
break
|
||||
current += 1
|
||||
return records
|
||||
raise ModelHubAPIError("Task history pagination budget exhausted")
|
||||
|
||||
def add_task(self, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
return self._request("POST", "/api/adapt/task/add", data=payload)
|
||||
@@ -923,17 +934,26 @@ class ModelHubClientPool:
|
||||
# Default: use only the reader client to avoid fanout amplification.
|
||||
# The fanout_all parameter allows explicit cross-account merging when needed.
|
||||
fanout_all = kwargs.pop("_fanout_all", False)
|
||||
strict = kwargs.pop("_strict", False)
|
||||
if not fanout_all:
|
||||
if strict:
|
||||
return self._reader.list_tasks(**kwargs)
|
||||
return self._safe_list_tasks(self._reader, kwargs)
|
||||
|
||||
merged: list[dict[str, Any]] = []
|
||||
seen: set[str] = set()
|
||||
with ThreadPoolExecutor(max_workers=min(len(self.clients), 12)) as executor:
|
||||
futures = {executor.submit(self._safe_list_tasks, client, kwargs): index for index, client in enumerate(self.clients)}
|
||||
futures = {
|
||||
(executor.submit(client.list_tasks, **kwargs) if strict else
|
||||
executor.submit(self._safe_list_tasks, client, kwargs)): index
|
||||
for index, client in enumerate(self.clients)
|
||||
}
|
||||
for future in as_completed(futures):
|
||||
try:
|
||||
tasks = future.result()
|
||||
except Exception:
|
||||
if strict:
|
||||
raise ModelHubAPIError("Incomplete cross-account task history") from None
|
||||
tasks = []
|
||||
for task in tasks:
|
||||
task_id = str(task.get("taskId")) if task.get("taskId") is not None else None
|
||||
|
||||
Reference in new issue
Block a user