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:
+15
-1
@@ -116,12 +116,15 @@ def fetch_all_packages():
|
||||
version = "2022-01-01"
|
||||
all_packages = []
|
||||
current_token = ""
|
||||
seen_tokens = set()
|
||||
|
||||
while True:
|
||||
try:
|
||||
payload = {
|
||||
"ResourceType": "Package",
|
||||
"MaxResults": "20",
|
||||
# 只拉生效中的数据包,跳过 UsedUp/Expired/Refunded 等余额为 0 的无用包
|
||||
"Status": "Effective",
|
||||
"NextToken": current_token,
|
||||
}
|
||||
headers, body = get_signed_headers(action, version, payload)
|
||||
@@ -134,8 +137,19 @@ def fetch_all_packages():
|
||||
if items:
|
||||
all_packages.extend(items)
|
||||
next_token = data.get("Result", {}).get("NextToken", "")
|
||||
if not next_token or next_token == current_token:
|
||||
|
||||
# Infinite Loop Protection: VolcEngine API 翻页到头后 NextToken 会
|
||||
# 循环回起始 token(实测:数据只有 ~8 页,第 9 页绕回第一个 token),
|
||||
# 没有该保护会无限翻页。
|
||||
if not next_token:
|
||||
break
|
||||
if next_token == current_token:
|
||||
break
|
||||
if next_token in seen_tokens:
|
||||
print(f"WARNING: Detected pagination cycle with token {next_token}. Stopping.")
|
||||
break
|
||||
|
||||
seen_tokens.add(next_token)
|
||||
current_token = next_token
|
||||
time.sleep(0.2)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user