chore: first commit
This commit is contained in:
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user