Add training job status in the db
This commit is contained in:
@@ -13,7 +13,7 @@ from datetime import datetime, timezone
|
||||
import uuid
|
||||
|
||||
from app.core.database import get_db, get_background_db_session
|
||||
from app.services.training_service import TrainingService
|
||||
from app.services.training_service import TrainingService, TrainingStatusManager
|
||||
from sqlalchemy import select, delete, func
|
||||
from app.schemas.training import (
|
||||
TrainingJobRequest,
|
||||
@@ -172,10 +172,20 @@ async def execute_training_job_background(
|
||||
# ✅ FIX: Create training service with isolated DB session
|
||||
training_service = TrainingService(db_session=db_session)
|
||||
|
||||
status_manager = TrainingStatusManager(db_session=db_session)
|
||||
|
||||
# Publish progress event
|
||||
await publish_job_progress(job_id, tenant_id, 5, "Initializing training pipeline")
|
||||
|
||||
try:
|
||||
|
||||
await status_manager.update_job_status(
|
||||
job_id=job_id,
|
||||
status="running",
|
||||
progress=0,
|
||||
current_step="Initializing training pipeline"
|
||||
)
|
||||
|
||||
# Execute the actual training pipeline
|
||||
result = await training_service.start_training_job(
|
||||
tenant_id=tenant_id,
|
||||
@@ -185,6 +195,14 @@ async def execute_training_job_background(
|
||||
requested_end=requested_end
|
||||
)
|
||||
|
||||
await status_manager.update_job_status(
|
||||
job_id=job_id,
|
||||
status="completed",
|
||||
progress=100,
|
||||
current_step="Training completed successfully",
|
||||
results=result
|
||||
)
|
||||
|
||||
# Publish completion event
|
||||
await publish_job_completed(
|
||||
job_id=job_id,
|
||||
@@ -196,7 +214,15 @@ async def execute_training_job_background(
|
||||
|
||||
except Exception as training_error:
|
||||
logger.error(f"❌ Training pipeline failed for job {job_id}: {str(training_error)}")
|
||||
|
||||
|
||||
await status_manager.update_job_status(
|
||||
job_id=job_id,
|
||||
status="failed",
|
||||
progress=0,
|
||||
current_step="Training failed",
|
||||
error_message=str(training_error)
|
||||
)
|
||||
|
||||
# Publish failure event
|
||||
await publish_job_failed(
|
||||
job_id=job_id,
|
||||
|
||||
Reference in New Issue
Block a user