fix: 修复 PDD 页面误判与失败回执 (#35)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""使用 Python 标准库调用 Admin 登记和任务领取接口。"""
|
||||
"""使用 Python 标准库调用 Admin 登记、领取和提交接口。"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import socket
|
||||
from http.client import RemoteDisconnected
|
||||
@@ -306,6 +307,24 @@ class HttpAdminGateway(AdminGateway):
|
||||
accepted = data.get("accepted")
|
||||
result_id = data.get("result_id")
|
||||
accepted_at = data.get("accepted_at")
|
||||
legacy_failure = (
|
||||
endpoint == "failure"
|
||||
and accepted is True
|
||||
and isinstance(accepted_at, str)
|
||||
and bool(accepted_at.strip())
|
||||
and isinstance(data.get("task_status"), str)
|
||||
and bool(data["task_status"].strip())
|
||||
and not (isinstance(result_id, str) and result_id.strip())
|
||||
)
|
||||
if legacy_failure:
|
||||
digest = hashlib.sha256(
|
||||
idempotency_key.encode("utf-8")
|
||||
).hexdigest()[:16]
|
||||
return SubmissionReceipt(
|
||||
True,
|
||||
f"legacy-failure-{digest}",
|
||||
accepted_at,
|
||||
)
|
||||
if (
|
||||
accepted is not True
|
||||
or not isinstance(result_id, str)
|
||||
@@ -315,8 +334,8 @@ class HttpAdminGateway(AdminGateway):
|
||||
):
|
||||
raise AdminGatewayError(
|
||||
"ADMIN_INVALID_RESPONSE",
|
||||
"Admin 提交响应字段不完整",
|
||||
False,
|
||||
"Admin 返回成功状态,但响应格式异常,数据可能已接收,将安全重试",
|
||||
True,
|
||||
request_id,
|
||||
)
|
||||
return SubmissionReceipt(True, result_id, accepted_at)
|
||||
|
||||
Reference in New Issue
Block a user