Skip to content

Commit

Permalink
sprintfix: 修复任务未执行完成却判定为成功的问题 (closed #1348) (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Jul 12, 2023
1 parent bde076b commit f81a3e3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions apps/backend/subscription/task_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
import traceback
from collections import defaultdict
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

from django.db import transaction
from django.db.models import QuerySet
Expand Down Expand Up @@ -68,13 +68,22 @@ def collect_status(steps: List[Dict[str, Any]], backtrace_steps=False) -> str:
elif constants.JobStatusType.RUNNING in status_set:
status = constants.JobStatusType.RUNNING

# 如果 steps 中都是 Pending 那返回的 status 也是 Pending
if not status_set == {constants.JobStatusType.PENDING} and backtrace_steps:
# 如果 steps 中都是 Pending 那返回的 status 也是 Pending
if status_set != {constants.JobStatusType.PENDING} and backtrace_steps:
# 填充 steps 中的状态
for step in steps:
if step["status"] in [constants.JobStatusType.FAILED, constants.JobStatusType.RUNNING]:
break
else:
# 1. 找到第一个 RUNNING / FAILED 的节点索引
index: Optional[int] = next(
(
i
for i, step in enumerate(steps)
if step["status"] in [constants.JobStatusType.FAILED, constants.JobStatusType.RUNNING]
),
None,
)

# 2. 如果找到,将前面的状态都填充为成功
if index is not None:
for step in steps[:index]:
step["status"] = constants.JobStatusType.SUCCESS

return status
Expand Down

0 comments on commit f81a3e3

Please sign in to comment.