Skip to content

Commit 02c0347

Browse files
committed
feat: timeout
1 parent e4000c7 commit 02c0347

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

server/python/api/router/task.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ async def _upload(item: dict, task_length: int):
309309
break
310310

311311
elif res["result"] in ["doing"]: # doing / other
312-
if (now - begin).seconds > 5 * 60: # 超时
312+
if (now - begin).seconds > 2 * 60: # 超时
313313
update_status(
314314
id=item["id"],
315315
status="上传失败,代码上传密钥疑似错误",
@@ -392,46 +392,52 @@ async def _task():
392392
"成功" not in (x["status"] or ""),
393393
not x["upload_at"],
394394
"失败" not in (x["status"] or ""),
395-
x["create_at"],
395+
x["upload_at"] or MIN_TIME,
396396
),
397397
reverse=True,
398398
)
399399
logging.info(
400400
f"当前任务总数 {len(_list2)},未完成任务数 {len(_list3)},本轮处理任务数 {len(_list)}"
401401
)
402402

403-
for index, item in enumerate(_list):
404-
item["task-index"] = index + 1
405-
await asyncio.sleep(0.1)
403+
async def _upload_task(_list):
404+
for index, item in enumerate(_list):
405+
item["task-index"] = index + 1
406+
await asyncio.sleep(0.1)
406407

407-
if len(item["appid"]) != 18:
408-
update_status(id=item["id"], status="校验失败,AppID不是18位")
409-
continue
410-
if len(item["mobile"]) != 11:
411-
update_status(id=item["id"], status="校验失败,手机号不是11位")
412-
continue
413-
if len(item["key"]) < 1000:
414-
update_status(id=item["id"], status="校验失败,代码上传密钥明细错误")
415-
continue
416-
item["key"] = _handle_key(item)
417-
if not item["key"]:
418-
update_status(id=item["id"], status="校验失败,无效的代码上传密钥")
419-
continue
408+
if len(item["appid"]) != 18:
409+
update_status(id=item["id"], status="校验失败,AppID不是18位")
410+
continue
411+
if len(item["mobile"]) != 11:
412+
update_status(id=item["id"], status="校验失败,手机号不是11位")
413+
continue
414+
if len(item["key"]) < 1000:
415+
update_status(
416+
id=item["id"], status="校验失败,代码上传密钥明细错误"
417+
)
418+
continue
419+
item["key"] = _handle_key(item)
420+
if not item["key"]:
421+
update_status(id=item["id"], status="校验失败,无效的代码上传密钥")
422+
continue
420423

421-
await _auth_check(item)
424+
await _auth_check(item)
422425

423-
try:
424-
await asyncio.wait_for(_upload(item, len(_list)), timeout=5 * 60)
425-
except asyncio.TimeoutError:
426-
continue
426+
try:
427+
await asyncio.wait_for(_upload(item, len(_list)), timeout=3 * 60)
428+
except asyncio.TimeoutError:
429+
continue
430+
431+
try:
432+
await asyncio.wait_for(_upload_task(_list), timeout=len(_list) * 3 * 60)
433+
except asyncio.TimeoutError:
434+
logging.info("任务处理超时")
427435

428436
logging.info("任务处理完成")
429437

430438
while True:
431439
try:
432-
await asyncio.wait_for(_task(), timeout=2 * 3600)
433-
except asyncio.TimeoutError:
434-
logging.info("任务处理超时")
440+
_task()
435441
except Exception as e:
436442
logging.warning(f"任务处理异常 {e} {e.__class__.__name__}", exc_info=True)
437443
else:

0 commit comments

Comments
 (0)