fix: 资源包查询修复翻页死循环并加 Status 过滤

- debug_volc_sync.py 缺少 seen_tokens 防循环保护,火山 API 翻页到头后
  NextToken 循环回起始 token,导致无限翻页(实测 900s 拉 1893 页假象,
  真实数据仅 8 页 137 个包)
- 两个 fetch_all_packages 请求加 Status=Effective,服务端直接过滤
  UsedUp/Expired/Refunded 等余额为 0 的无用包(实测过滤后 0 余额包为 0)
- 主脚本循环检测日志从 DEBUG 提升为 WARNING,循环收尾不再静默
This commit is contained in:
root
2026-08-11 03:39:57 +00:00
parent e29d94f9e8
commit 8feb38db37
2 changed files with 26 additions and 5 deletions
+11 -4
View File
@@ -863,6 +863,10 @@ def fetch_all_packages():
payload = {
"ResourceType": "Package",
"MaxResults": "20",
# 服务端只返回生效中的数据包,跳过 UsedUp/Expired/Refunded 等
# 余额为 0 的无用包,显著减少翻页次数与 QPS 占用。
# 周期型包(月度重置)状态仍为 Effective,不会被误过滤。
"Status": "Effective",
"NextToken": current_token,
}
headers, body = get_signed_headers(action, version, payload)
@@ -876,15 +880,18 @@ def fetch_all_packages():
next_token = data.get("Result", {}).get("NextToken", "")
# Infinite Loop Protection
# 火山 API 翻页到头后 NextToken 会循环回起始 token(实测数据只有
# ~8 页时第 9 页绕回第一个 token),必须用 seen_tokens 拦下载断。
if not next_token:
break
if next_token == current_token:
break
if next_token in seen_tokens:
if DEBUG_MODE:
print(
f"DEBUG: Detected pagination cycle with token {next_token}. Stopping."
)
log(
f"⚠️ VolcEngine pagination cycle detected (token {next_token} repeated). "
f"Stopping after {len(all_packages)} packages.",
level="WARNING",
)
break
seen_tokens.add(next_token)