Commit_all_local_changes_after_PR_406_merge

This commit is contained in:
ajaysi
2026-03-10 17:01:36 +05:30
parent f78b5f1e04
commit 8c2d88efb9
17 changed files with 936 additions and 412 deletions

View File

@@ -18,6 +18,26 @@ router = APIRouter()
UPLOAD_DIR = Path("backend/data/video_studio/uploads")
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
def _extract_error_metadata(exc: Exception) -> Dict[str, Any]:
"""Extract structured HTTP error metadata for polling clients."""
if isinstance(exc, HTTPException):
detail = exc.detail
if isinstance(detail, dict):
return {
"error_status": exc.status_code,
"error_data": detail,
}
if isinstance(detail, str):
return {
"error_status": exc.status_code,
"error_data": {
"error": detail,
"message": detail,
},
}
return {}
def _process_avatar_generation(task_id: str, image_path: Path, audio_path: Path, user_id: str, resolution: str, model: str):
"""
Background task to process avatar generation using shared InfiniteTalk service.
@@ -94,7 +114,15 @@ def _process_avatar_generation(task_id: str, image_path: Path, audio_path: Path,
except Exception as e:
logger.error(f"[VideoStudio] Avatar generation failed for task {task_id}: {e}", exc_info=True)
task_manager.update_task(task_id, "failed", error=str(e), user_id=user_id)
error_meta = _extract_error_metadata(e)
task_manager.update_task(
task_id,
"failed",
error=str(e),
user_id=user_id,
error_status=error_meta.get("error_status"),
error_data=error_meta.get("error_data"),
)
finally:
# Cleanup temp upload files
try:

View File

@@ -39,7 +39,18 @@ class TaskManager:
logger.error(f"[VideoStudio] Failed to create task: {e}")
raise
def update_task(self, task_id: str, status: str, result: Optional[Dict] = None, error: Optional[str] = None, user_id: str = None, progress: float = None, message: str = None):
def update_task(
self,
task_id: str,
status: str,
result: Optional[Dict] = None,
error: Optional[str] = None,
user_id: str = None,
progress: float = None,
message: str = None,
error_status: Optional[int] = None,
error_data: Optional[Dict[str, Any]] = None,
):
"""Update an existing task."""
if not user_id:
logger.error(f"[VideoStudio] Cannot update task {task_id} without user_id")
@@ -74,6 +85,13 @@ class TaskManager:
task.result = result
if error:
task.error = error
if error_status is not None or error_data is not None:
result_payload = task.result if isinstance(task.result, dict) else {}
if error_status is not None:
result_payload["error_status"] = error_status
if error_data is not None:
result_payload["error_data"] = error_data
task.result = result_payload
if progress is not None:
task.progress = progress
if message:
@@ -107,7 +125,7 @@ class TaskManager:
if status_val == "processing":
status_val = "running"
return {
response = {
"task_id": task.task_id,
"status": status_val,
"result": task.result,
@@ -117,6 +135,12 @@ class TaskManager:
"created_at": task.created_at,
"updated_at": task.updated_at
}
if isinstance(task.result, dict):
if task.result.get("error_status") is not None:
response["error_status"] = task.result.get("error_status")
if task.result.get("error_data") is not None:
response["error_data"] = task.result.get("error_data")
return response
finally:
db.close()
except Exception as e: