fix: label-ocr 防重入改用客户端过滤 RUNNING 状态
This commit is contained in:
+6
-4
@@ -33,7 +33,7 @@ def _result_to_fields(r) -> dict[str, str | None]:
|
||||
|
||||
|
||||
def _has_running_peer() -> bool:
|
||||
"""检查是否有同类 flow run 正在运行(查到 >1 个说明有其他实例)。"""
|
||||
"""检查是否有同类 flow run 正在运行(查到 >1 个 RUNNING 说明有其他实例)。"""
|
||||
api_url = os.environ.get("PREFECT_API_URL", "http://localhost:4200/api")
|
||||
dep_id = str(deployment.id) if deployment.id else ""
|
||||
if not dep_id:
|
||||
@@ -43,13 +43,15 @@ def _has_running_peer() -> bool:
|
||||
f"{api_url}/flow_runs/filter",
|
||||
json={
|
||||
"flow_runs": {"deployment_id": {"any_": [dep_id]}},
|
||||
"state": {"type": {"any_": ["RUNNING"]}},
|
||||
"limit": 10,
|
||||
"sort": "START_TIME_DESC",
|
||||
},
|
||||
params={"limit": 10},
|
||||
timeout=10,
|
||||
)
|
||||
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:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user