deving
This commit is contained in:
+32
-6
@@ -116,14 +116,40 @@ async def upload_stp(
|
||||
|
||||
@router.get("/status/{task_id}")
|
||||
@router.post("/status/{task_id}")
|
||||
async def get_status(task_id: str):
|
||||
async def get_status(task_id: str, db_session: AsyncSession = Depends(get_db_session)):
|
||||
"""获取任务状态"""
|
||||
if task_id not in tasks:
|
||||
from sqlalchemy import select
|
||||
from models.database import ProcessingTask, STPFile
|
||||
|
||||
# 从数据库查询任务详情
|
||||
result = await db_session.execute(
|
||||
select(ProcessingTask, STPFile)
|
||||
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
||||
.where(ProcessingTask.task_id == task_id)
|
||||
)
|
||||
|
||||
task_record = result.first()
|
||||
|
||||
if not task_record:
|
||||
raise HTTPException(404, "任务不存在")
|
||||
|
||||
task = tasks[task_id]
|
||||
logger.info(f"返回任务状态: {task_id} - {task['status']}")
|
||||
return task
|
||||
|
||||
task, stp_file = task_record
|
||||
|
||||
# 构建任务详情数据
|
||||
task_data = {
|
||||
"task_id": task.task_id,
|
||||
"filename": stp_file.original_filename if stp_file else "",
|
||||
"file_size": stp_file.file_size if stp_file else 0,
|
||||
"status": task.status,
|
||||
"progress": task.progress,
|
||||
"current_step": task.current_step,
|
||||
"upload_time": task.created_time.isoformat() if task.created_time else "",
|
||||
"completed_at": task.completed_time.isoformat() if task.completed_time else "",
|
||||
"error": task.error_message if task.error_message else ""
|
||||
}
|
||||
|
||||
logger.info(f"返回任务状态: {task_id} - {task.status}")
|
||||
return task_data
|
||||
|
||||
|
||||
@router.get("/debug/tasks")
|
||||
|
||||
Reference in New Issue
Block a user