fix: label-ocr 防重入改用客户端过滤 RUNNING 状态

This commit is contained in:
yeuimu
2026-07-31 05:46:38 +00:00
parent f8b8db2d79
commit 4b2ef120b5
+6 -4
View File
@@ -33,7 +33,7 @@ def _result_to_fields(r) -> dict[str, str | None]:
def _has_running_peer() -> bool: def _has_running_peer() -> bool:
"""检查是否有同类 flow run 正在运行(查到 >1 个说明有其他实例)。""" """检查是否有同类 flow run 正在运行(查到 >1 个 RUNNING 说明有其他实例)。"""
api_url = os.environ.get("PREFECT_API_URL", "http://localhost:4200/api") api_url = os.environ.get("PREFECT_API_URL", "http://localhost:4200/api")
dep_id = str(deployment.id) if deployment.id else "" dep_id = str(deployment.id) if deployment.id else ""
if not dep_id: if not dep_id:
@@ -43,13 +43,15 @@ def _has_running_peer() -> bool:
f"{api_url}/flow_runs/filter", f"{api_url}/flow_runs/filter",
json={ json={
"flow_runs": {"deployment_id": {"any_": [dep_id]}}, "flow_runs": {"deployment_id": {"any_": [dep_id]}},
"state": {"type": {"any_": ["RUNNING"]}}, "limit": 10,
"sort": "START_TIME_DESC",
}, },
params={"limit": 10},
timeout=10, timeout=10,
) )
resp.raise_for_status() resp.raise_for_status()
return len(resp.json()) > 1 runs = resp.json()
running = sum(1 for r in runs if r.get("state", {}).get("type") == "RUNNING")
return running > 1
except Exception: except Exception:
return False return False