From 4b2ef120b57424152e518bba3445a0a5fb8f6b7d Mon Sep 17 00:00:00 2001 From: yeuimu <2197651308@qq.com> Date: Fri, 31 Jul 2026 05:46:38 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20label-ocr=20=E9=98=B2=E9=87=8D=E5=85=A5?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=20RUNNING=20=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flows/label_ocr.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flows/label_ocr.py b/flows/label_ocr.py index aad64af..3909e5a 100644 --- a/flows/label_ocr.py +++ b/flows/label_ocr.py @@ -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