fix: label-ocr 防重入改用 count>1 避免自检

This commit is contained in:
yeuimu
2026-07-31 05:44:52 +00:00
parent 68f0d9439c
commit f8b8db2d79
+3 -4
View File
@@ -10,7 +10,7 @@ import os
import httpx import httpx
from prefect import flow, task from prefect import flow, task
from prefect.runtime import deployment, flow_run from prefect.runtime import deployment
from api.ocr import OcrClient, country_to_ocr_code from api.ocr import OcrClient, country_to_ocr_code
from flows.shared import SyncDB, build_stats_rows, emit_sync_summary from flows.shared import SyncDB, build_stats_rows, emit_sync_summary
@@ -33,9 +33,8 @@ def _result_to_fields(r) -> dict[str, str | None]:
def _has_running_peer() -> bool: def _has_running_peer() -> bool:
"""检查是否有同类 flow run 正在运行(排除自身)。""" """检查是否有同类 flow run 正在运行(查到 >1 个说明有其他实例)。"""
api_url = os.environ.get("PREFECT_API_URL", "http://localhost:4200/api") api_url = os.environ.get("PREFECT_API_URL", "http://localhost:4200/api")
cur_id = str(flow_run.id) if flow_run.id else ""
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:
return False return False
@@ -50,7 +49,7 @@ def _has_running_peer() -> bool:
timeout=10, timeout=10,
) )
resp.raise_for_status() resp.raise_for_status()
return any(r["id"] != cur_id for r in resp.json()) return len(resp.json()) > 1
except Exception: except Exception:
return False return False