chore: first commit

This commit is contained in:
Daniil
2026-02-17 23:33:08 +03:00
parent a25bf623ea
commit 937e58859a
3 changed files with 411 additions and 254 deletions
+8 -14
View File
@@ -7,7 +7,7 @@ from __future__ import annotations
import uuid
from typing import cast
from fastapi import APIRouter, Depends, HTTPException, Request, status
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from cpv3.db.session import get_db
@@ -22,6 +22,7 @@ from cpv3.modules.tasks.schemas import (
TaskStatusResponse,
TaskSubmitResponse,
TaskTypeEnum,
TaskWebhookEvent,
TranscriptionGenerateRequest,
)
from cpv3.modules.tasks.service import TaskService
@@ -146,23 +147,16 @@ async def get_task_status(
@router.post("/webhook/{job_id}/", include_in_schema=False)
async def task_webhook_callback(
job_id: uuid.UUID,
request: Request,
body: TaskWebhookEvent,
db: AsyncSession = Depends(get_db),
) -> dict[str, str]:
"""Internal webhook endpoint for task status updates."""
service = TaskService(db)
try:
await request.json()
except Exception:
await service.record_webhook_event(job_id=job_id, event=body)
except ValueError as exc:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid JSON payload"
)
job_service = JobService(db)
job = await job_service.get_job(job_id)
if job is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Job not found"
)
status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)
) from exc
return {"status": "received", "job_id": str(job_id)}