diff --git a/flows/label_ocr.py b/flows/label_ocr.py index 5e1ceff..aad64af 100644 --- a/flows/label_ocr.py +++ b/flows/label_ocr.py @@ -10,7 +10,7 @@ import os import httpx 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 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: - """检查是否有同类 flow run 正在运行(排除自身)。""" + """检查是否有同类 flow run 正在运行(查到 >1 个说明有其他实例)。""" 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 "" if not dep_id: return False @@ -50,7 +49,7 @@ def _has_running_peer() -> bool: timeout=10, ) resp.raise_for_status() - return any(r["id"] != cur_id for r in resp.json()) + return len(resp.json()) > 1 except Exception: return False