debug
This commit is contained in:
@@ -842,6 +842,15 @@ def _push_projection_record(source_record: dict, sync_type: str, ingest_url: str
|
||||
raw = response.read().decode("utf-8")
|
||||
data = json.loads(raw) if raw else {}
|
||||
status_code = getattr(response, "status", 200)
|
||||
except json.JSONDecodeError as exc:
|
||||
payload = {
|
||||
"sync_type": sync_type,
|
||||
"source_record_id": source_record["id"],
|
||||
"projection_hash": request_payload["projection_hash"],
|
||||
"ingest_url": ingest_url,
|
||||
}
|
||||
_update_push_attempt(attempt_id, status="failed", payload=payload, error_message=f"invalid json response: {exc}")
|
||||
return False, f"同步推送失败: 远端响应不是合法 JSON ({exc})", {"action": "push_sync", "sync_type": sync_type, "attempt_id": attempt_id}
|
||||
except urllib.error.HTTPError as exc:
|
||||
error_body = exc.read().decode("utf-8", errors="ignore") if hasattr(exc, "read") else ""
|
||||
payload = {
|
||||
@@ -872,6 +881,21 @@ def _push_projection_record(source_record: dict, sync_type: str, ingest_url: str
|
||||
"http_status": status_code,
|
||||
"response": data,
|
||||
}
|
||||
response_code = data.get("code", 0)
|
||||
if response_code not in (0, "0", None, ""):
|
||||
_update_push_attempt(
|
||||
attempt_id,
|
||||
status="failed",
|
||||
payload=payload,
|
||||
error_message=str(data.get("message") or "remote business error"),
|
||||
)
|
||||
return False, f"同步推送失败: {str(data.get('message') or '远端业务返回失败')}", {
|
||||
"action": "push_sync",
|
||||
"sync_type": sync_type,
|
||||
"attempt_id": attempt_id,
|
||||
"source_record_id": source_record["id"],
|
||||
"response": data,
|
||||
}
|
||||
_update_push_attempt(attempt_id, status="success", payload=payload, error_message="")
|
||||
return True, "投影推送成功", {
|
||||
"action": "push_sync",
|
||||
@@ -923,6 +947,8 @@ def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dic
|
||||
with urllib.request.urlopen(request, timeout=20) as response:
|
||||
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"}
|
||||
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)}", {
|
||||
@@ -978,6 +1004,22 @@ def pull_detect_task_batch_now(limit: int | None = None) -> tuple[bool, str, dic
|
||||
raw = response.read().decode("utf-8")
|
||||
ack_response = json.loads(raw) if raw else {}
|
||||
ack_data = ack_response.get("data") or {}
|
||||
ack_code = ack_response.get("code", 0)
|
||||
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",
|
||||
"source_record_id": source_record_id,
|
||||
"projection_hash": projection_hash,
|
||||
**(ingest_data or {}),
|
||||
"ack": ack_data,
|
||||
"ack_response": ack_response,
|
||||
}
|
||||
except json.JSONDecodeError as exc:
|
||||
return True, f"{ingest_message};但远端确认失败: ack 响应不是合法 JSON ({exc})", {
|
||||
"action": "pull_tasks",
|
||||
"source_record_id": source_record_id,
|
||||
**(ingest_data or {}),
|
||||
}
|
||||
except Exception as exc:
|
||||
return True, f"{ingest_message};但远端确认失败: {exc}", {
|
||||
"action": "pull_tasks",
|
||||
|
||||
Reference in New Issue
Block a user