条件单列表改为中控后台并行缓存并以 SSE 推浏览器,下发仍走中控到实例。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -215,6 +215,40 @@ def fetch_cond_orders(inst: dict[str, Any]) -> dict[str, Any]:
|
||||
return {"ok": False, "msg": str(e) or "拉取失败", "orders": [], "instance_id": inst.get("id")}
|
||||
|
||||
|
||||
def pull_all_cond_orders() -> list[dict[str, Any]]:
|
||||
"""并行拉取各机条件单并展平为带 instance 字段的订单列表."""
|
||||
instances = list_instances(enabled_only=True)
|
||||
if not instances:
|
||||
return []
|
||||
by_id: dict[Any, dict[str, Any]] = {}
|
||||
with ThreadPoolExecutor(max_workers=min(8, len(instances))) as pool:
|
||||
futs = {pool.submit(fetch_cond_orders, inst): inst for inst in instances}
|
||||
for fut in as_completed(futs):
|
||||
inst = futs[fut]
|
||||
try:
|
||||
data = fut.result()
|
||||
except Exception as e:
|
||||
data = {
|
||||
"ok": False,
|
||||
"msg": str(e) or "拉取失败",
|
||||
"orders": [],
|
||||
"instance_id": inst.get("id"),
|
||||
"instance_name": inst.get("name"),
|
||||
}
|
||||
by_id[inst.get("id")] = data if isinstance(data, dict) else {}
|
||||
all_orders: list[dict[str, Any]] = []
|
||||
for inst in instances:
|
||||
data = by_id.get(inst["id"]) or {}
|
||||
for o in data.get("orders") or []:
|
||||
if not isinstance(o, dict):
|
||||
continue
|
||||
item = dict(o)
|
||||
item["instance_id"] = inst.get("id")
|
||||
item["instance_name"] = inst.get("name")
|
||||
all_orders.append(item)
|
||||
return all_orders
|
||||
|
||||
|
||||
def pull_all_enabled() -> list[dict[str, Any]]:
|
||||
instances = list_instances(enabled_only=True)
|
||||
if not instances:
|
||||
|
||||
Reference in New Issue
Block a user