debug
This commit is contained in:
@@ -908,11 +908,11 @@ def _push_projection_record(source_record: dict, sync_type: str, ingest_url: str
|
||||
|
||||
def push_runtime_projection_now() -> tuple[bool, str, dict]:
|
||||
if not settings.sync_push_enabled:
|
||||
return False, "未启用同步推送", {"action": "push_sync"}
|
||||
return False, "未启用同步推送", {"action": "push_sync", "sync_state": "disabled", "ui_level": "warning", "poll_schedule_seconds": []}
|
||||
|
||||
ingest_url = _ingest_url(settings.sync_target_api_base_url)
|
||||
if not ingest_url:
|
||||
return False, "未配置同步目标地址", {"action": "push_sync"}
|
||||
return False, "未配置同步目标地址", {"action": "push_sync", "sync_state": "misconfigured", "ui_level": "warning", "poll_schedule_seconds": []}
|
||||
|
||||
results = []
|
||||
ok, message, data = _push_projection_now("runtime_projection", ingest_url)
|
||||
@@ -922,19 +922,52 @@ def push_runtime_projection_now() -> tuple[bool, str, dict]:
|
||||
results.append({"sync_type": "detect_result_projection", "ok": ok, "message": message, "data": data})
|
||||
|
||||
success_count = sum(1 for item in results if item["ok"])
|
||||
warning_count = sum(
|
||||
1
|
||||
for item in results
|
||||
if not item["ok"] and any(keyword in str(item.get("message") or "") for keyword in ("当前没有可推送", "已全部同步完成", "无需重复发送", "进行中", "等待下个重试窗口"))
|
||||
)
|
||||
if success_count == 0:
|
||||
return False, "当前没有成功推送的同步投影", {"action": "push_sync", "results": results}
|
||||
return True, f"同步推送完成,成功 {success_count}/{len(results)}", {"action": "push_sync", "results": results}
|
||||
if warning_count == len(results):
|
||||
return False, "当前没有需要立即推送的同步投影", {
|
||||
"action": "push_sync",
|
||||
"sync_state": "idle",
|
||||
"ui_level": "warning",
|
||||
"poll_schedule_seconds": [],
|
||||
"results": results,
|
||||
}
|
||||
return False, "同步推送未成功,请检查明细结果", {
|
||||
"action": "push_sync",
|
||||
"sync_state": "failed",
|
||||
"ui_level": "error",
|
||||
"poll_schedule_seconds": [2],
|
||||
"results": results,
|
||||
}
|
||||
if success_count < len(results):
|
||||
return True, f"同步推送部分完成,成功 {success_count}/{len(results)}", {
|
||||
"action": "push_sync",
|
||||
"sync_state": "partial_success",
|
||||
"ui_level": "warning",
|
||||
"poll_schedule_seconds": [1, 3],
|
||||
"results": results,
|
||||
}
|
||||
return True, f"同步推送完成,成功 {success_count}/{len(results)}", {
|
||||
"action": "push_sync",
|
||||
"sync_state": "success",
|
||||
"ui_level": "success",
|
||||
"poll_schedule_seconds": [1, 3],
|
||||
"results": results,
|
||||
}
|
||||
|
||||
|
||||
def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dict]:
|
||||
if settings.node_region != "mainland" or settings.node_role != "control":
|
||||
return False, "当前节点无需拉取待检测任务批次", {"action": "pull_tasks"}
|
||||
return False, "当前节点无需拉取待检测任务批次", {"action": "pull_tasks", "pull_state": "not_applicable", "ui_level": "warning", "poll_schedule_seconds": []}
|
||||
|
||||
export_url = _task_export_url(settings.sync_target_api_base_url)
|
||||
ack_url = _task_ack_url(settings.sync_target_api_base_url)
|
||||
if not export_url or not ack_url:
|
||||
return False, "未配置任务拉取目标地址", {"action": "pull_tasks"}
|
||||
return False, "未配置任务拉取目标地址", {"action": "pull_tasks", "pull_state": "misconfigured", "ui_level": "warning", "poll_schedule_seconds": []}
|
||||
|
||||
safe_limit = max(1, min(int(limit or settings.sync_batch_size or 200), max(1, int(settings.sync_batch_size or 200))))
|
||||
request_url = f"{export_url}?limit={safe_limit}"
|
||||
@@ -948,27 +981,30 @@ def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dic
|
||||
raw = response.read().decode("utf-8")
|
||||
data = json.loads(raw) if raw else {}
|
||||
except json.JSONDecodeError as exc:
|
||||
return False, f"拉取待检测任务失败: 远端响应不是合法 JSON ({exc})", {"action": "pull_tasks"}
|
||||
return False, f"拉取待检测任务失败: 远端响应不是合法 JSON ({exc})", {"action": "pull_tasks", "pull_state": "failed", "ui_level": "error", "poll_schedule_seconds": [2]}
|
||||
except urllib.error.HTTPError as exc:
|
||||
error_body = exc.read().decode("utf-8", errors="ignore") if hasattr(exc, "read") else ""
|
||||
return False, f"拉取待检测任务失败: HTTP {getattr(exc, 'code', 500)}", {
|
||||
"action": "pull_tasks",
|
||||
"pull_state": "failed",
|
||||
"ui_level": "error",
|
||||
"poll_schedule_seconds": [2],
|
||||
"http_status": getattr(exc, "code", 500),
|
||||
"response_text": error_body[:500],
|
||||
}
|
||||
except Exception as exc:
|
||||
return False, f"拉取待检测任务失败: {exc}", {"action": "pull_tasks"}
|
||||
return False, f"拉取待检测任务失败: {exc}", {"action": "pull_tasks", "pull_state": "failed", "ui_level": "error", "poll_schedule_seconds": [2]}
|
||||
|
||||
payload = data.get("data") or {}
|
||||
response_code = data.get("code", 0)
|
||||
if response_code not in (0, "0", None) and not payload:
|
||||
return False, str(data.get("message") or "拉取待检测任务失败"), {"action": "pull_tasks", "response": data}
|
||||
return False, str(data.get("message") or "拉取待检测任务失败"), {"action": "pull_tasks", "pull_state": "failed", "ui_level": "error", "poll_schedule_seconds": [2], "response": data}
|
||||
|
||||
source_record_id = int(payload.get("source_record_id") or 0)
|
||||
projection_hash = str(payload.get("projection_hash") or "").strip()
|
||||
projection = payload.get("projection") or {}
|
||||
if source_record_id <= 0 or not projection_hash or not projection:
|
||||
return False, "远端当前没有可拉取的待检测任务批次", {"action": "pull_tasks", "batch_size": 0}
|
||||
return False, "远端当前没有可拉取的待检测任务批次", {"action": "pull_tasks", "pull_state": "idle", "ui_level": "warning", "poll_schedule_seconds": [], "batch_size": 0}
|
||||
|
||||
ingest_ok, ingest_message, ingest_data = ingest_detect_task_projection(
|
||||
{
|
||||
@@ -981,7 +1017,7 @@ def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dic
|
||||
shared_token=settings.sync_shared_token,
|
||||
)
|
||||
if not ingest_ok:
|
||||
return False, ingest_message, {"action": "pull_tasks", **(ingest_data or {})}
|
||||
return False, ingest_message, {"action": "pull_tasks", "pull_state": "failed", "ui_level": "error", "poll_schedule_seconds": [2], **(ingest_data or {})}
|
||||
|
||||
ack_request = urllib.request.Request(
|
||||
ack_url,
|
||||
@@ -1008,6 +1044,9 @@ def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dic
|
||||
if ack_code not in (0, "0", None, ""):
|
||||
return True, f"{ingest_message};但远端确认失败: {str(ack_response.get('message') or 'ack business error')}", {
|
||||
"action": "pull_tasks",
|
||||
"pull_state": "ack_warning",
|
||||
"ui_level": "warning",
|
||||
"poll_schedule_seconds": [1, 3],
|
||||
"source_record_id": source_record_id,
|
||||
"projection_hash": projection_hash,
|
||||
**(ingest_data or {}),
|
||||
@@ -1017,18 +1056,27 @@ def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dic
|
||||
except json.JSONDecodeError as exc:
|
||||
return True, f"{ingest_message};但远端确认失败: ack 响应不是合法 JSON ({exc})", {
|
||||
"action": "pull_tasks",
|
||||
"pull_state": "ack_warning",
|
||||
"ui_level": "warning",
|
||||
"poll_schedule_seconds": [1, 3],
|
||||
"source_record_id": source_record_id,
|
||||
**(ingest_data or {}),
|
||||
}
|
||||
except Exception as exc:
|
||||
return True, f"{ingest_message};但远端确认失败: {exc}", {
|
||||
"action": "pull_tasks",
|
||||
"pull_state": "ack_warning",
|
||||
"ui_level": "warning",
|
||||
"poll_schedule_seconds": [1, 3],
|
||||
"source_record_id": source_record_id,
|
||||
**(ingest_data or {}),
|
||||
}
|
||||
|
||||
return True, "待检测任务批次拉取并入库成功", {
|
||||
"action": "pull_tasks",
|
||||
"pull_state": "success",
|
||||
"ui_level": "success",
|
||||
"poll_schedule_seconds": [1, 3],
|
||||
"source_record_id": source_record_id,
|
||||
"projection_hash": projection_hash,
|
||||
"batch_code": str(projection.get("batch_code") or "").strip(),
|
||||
|
||||
Reference in New Issue
Block a user