Fix data fetch 7
This commit is contained in:
@@ -153,7 +153,8 @@ async def get_training_job(
|
||||
job_id: str,
|
||||
tenant_id: UUID = Path(..., description="Tenant ID"),
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
training_service: TrainingService = Depends(get_training_service)
|
||||
training_service: TrainingService = Depends(get_training_service),
|
||||
db: AsyncSession = Depends(get_db_session)
|
||||
):
|
||||
"""Get specific training job details"""
|
||||
try:
|
||||
@@ -164,17 +165,24 @@ async def get_training_job(
|
||||
job_id=job_id,
|
||||
tenant_id=tenant_id_str)
|
||||
|
||||
job = await training_service.get_training_job(job_id)
|
||||
job_log = await training_service.get_job_status(db, job_id, tenant_id_str)
|
||||
|
||||
# Verify tenant access
|
||||
if job.tenant_id != tenant_id:
|
||||
if job_log.tenant_id != tenant_id:
|
||||
logger.warning("Unauthorized job access attempt",
|
||||
job_id=job_id,
|
||||
tenant_id=str(tenant_id),
|
||||
job_tenant_id=job.tenant_id)
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
||||
return job
|
||||
return TrainingJobResponse(
|
||||
job_id=job_log.job_id,
|
||||
status=TrainingStatus(job_log.status),
|
||||
message=_generate_status_message(job_log.status, job_log.current_step),
|
||||
tenant_id=str(job_log.tenant_id),
|
||||
created_at=job_log.start_time,
|
||||
estimated_duration_minutes=_estimate_duration(job_log.status, job_log.progress)
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
@@ -501,4 +509,31 @@ async def retrain_all_products(
|
||||
logger.error("Failed to start retraining",
|
||||
error=str(e),
|
||||
tenant_id=tenant_id)
|
||||
raise HTTPException(status_code=500, detail=f"Failed to start retraining: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=f"Failed to start retraining: {str(e)}")
|
||||
|
||||
def _generate_status_message(status: str, current_step: str) -> str:
|
||||
"""Generate appropriate status message"""
|
||||
status_messages = {
|
||||
"pending": "Training job is queued",
|
||||
"running": f"Training in progress: {current_step}",
|
||||
"completed": "Training completed successfully",
|
||||
"failed": "Training failed",
|
||||
"cancelled": "Training was cancelled"
|
||||
}
|
||||
return status_messages.get(status, f"Status: {status}")
|
||||
|
||||
def _estimate_duration(status: str, progress: int) -> int:
|
||||
"""Estimate remaining duration in minutes"""
|
||||
if status == "completed":
|
||||
return 0
|
||||
elif status == "failed" or status == "cancelled":
|
||||
return 0
|
||||
elif status == "pending":
|
||||
return 30 # Default estimate
|
||||
else: # running
|
||||
if progress > 0:
|
||||
# Rough estimate based on progress
|
||||
remaining_progress = 100 - progress
|
||||
return max(1, int((remaining_progress / max(progress, 1)) * 10))
|
||||
else:
|
||||
return 25 # Default for running jobs
|
||||
|
||||
Reference in New Issue
Block a user