haha
This commit is contained in:
@@ -181,7 +181,29 @@ def task_list(request):
|
||||
@api_view(["GET"])
|
||||
def task_detail(request, task_id):
|
||||
"""查询指定任务的状态和结果。"""
|
||||
# 先查内存
|
||||
task = task_dispatcher.get_task(task_id)
|
||||
if not task:
|
||||
if task:
|
||||
return api_success(_task_to_dict(task))
|
||||
|
||||
# 再查数据库(任务已完成的情况)
|
||||
try:
|
||||
from server.models import TaskLog
|
||||
task_log = TaskLog.objects.get(task_id=task_id)
|
||||
# 将数据库记录转换为相同格式
|
||||
task_dict = {
|
||||
"task_id": task_log.task_id,
|
||||
"task_type": task_log.task_type,
|
||||
"status": task_log.status,
|
||||
"worker_id": task_log.worker_id,
|
||||
"account_name": None,
|
||||
"params": task_log.params,
|
||||
"progress": None,
|
||||
"result": task_log.result,
|
||||
"error": task_log.error,
|
||||
"created_at": task_log.created_at.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"updated_at": task_log.created_at.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
}
|
||||
return api_success(task_dict)
|
||||
except Exception:
|
||||
return api_error(http_status.HTTP_404_NOT_FOUND, f"任务 {task_id} 不存在")
|
||||
return api_success(_task_to_dict(task))
|
||||
|
||||
Reference in New Issue
Block a user