fix: Add flush=True to print statements and improve task status check

- Added flush=True to print statements for better real-time logging
- Replaced single status check with a list of statuses to continue waiting
- Defined constants for task status values for better code readability
This commit is contained in:
bobo.yang 2025-03-21 19:28:49 +08:00
parent 0be6ca7e33
commit 42c4386562

View File

@ -48,13 +48,13 @@ def check_api_version():
return return
local_version = get_local_version() local_version = get_local_version()
print("检查被测服务器文档是否已经更新到最新版本...") print("检查被测服务器文档是否已经更新到最新版本...", flush=True)
while True: while True:
try: try:
res = session.get(VERSION_URL) res = session.get(VERSION_URL)
version = res.json()["version"] version = res.json()["version"]
if version == local_version: if version == local_version:
print(f"API 文档已更新,当前版本为 {version},开始上传 OpenAPI 文档...") print(f"API 文档已更新,当前版本为 {version},开始上传 OpenAPI 文档...", flush=True)
break break
else: else:
print( print(
@ -126,7 +126,11 @@ def wait_for_task_done(task_id):
res = session.get(f"{SERVER_URL}/tasks/{task_id}") res = session.get(f"{SERVER_URL}/tasks/{task_id}")
data = res.json() data = res.json()
status = data["status"] status = data["status"]
if status == "succeeded":
CREATED = "created"
RUNNING = "running"
WAITING = "waiting"
if status not in [CREATED, RUNNING, WAITING]:
print("自动测试脚本执行完成!", flush=True) print("自动测试脚本执行完成!", flush=True)
break break
else: else: