Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions backend/app/api/v1/endpoints/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,37 @@ def get_task_result(task_id: str, step: int = None, limit: int = 5):
raise HTTPException(500, f"Failed to get task result: {str(e)}")


@router.get("/execution/{task_id}/log", response_model=ApiResponse[List[str]], operation_id="get_execution_log", summary="获取任务日志")
def get_execution_log(task_id: str, operator_name: str = Query(None, description="算子名称")):
"""
获取任务日志

Args:
task_id: 任务 ID
operator_name: 算子名称(可选,指定时返回该算子的日志)

Returns:
日志列表
"""
try:
logger.info(f"Request: GET /execution/{task_id}/log, operator_name={operator_name}")

# 检查任务是否存在
task = container.task_registry.get(task_id)
if not task:
raise HTTPException(404, f"Task with id {task_id} not found")

logs = container.task_registry.get_execution_logs(task_id, operator_name)
Comment on lines +102 to +107
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint reads the registry twice: once to check if the task exists (line 103) and again in get_execution_logs (line 107). This could be optimized by having get_execution_logs return None for non-existent tasks, or by checking the returned logs and only raising a 404 if the task doesn't exist. Alternatively, the task existence check could be removed since get_execution_logs already handles non-existent tasks by returning an empty list, though this would change the error behavior.

Suggested change
# 检查任务是否存在
task = container.task_registry.get(task_id)
if not task:
raise HTTPException(404, f"Task with id {task_id} not found")
logs = container.task_registry.get_execution_logs(task_id, operator_name)
# 直接获取任务日志,如果任务不存在由日志结果判断
logs = container.task_registry.get_execution_logs(task_id, operator_name)
if logs is None:
raise HTTPException(404, f"Task with id {task_id} not found")

Copilot uses AI. Check for mistakes.

return ok(logs)

except HTTPException:
raise
except Exception as e:
logger.error(f"Failed to get task logs: {e}")
raise HTTPException(500, f"Failed to get task logs: {str(e)}")


@router.get("/execution/{task_id}/download", operation_id="download_task_result", summary="下载任务执行结果文件")
def download_task_result(task_id: str, step: int = None):
"""
Expand Down
Loading