feat: add api and mcp
This commit is contained in:
@@ -7,9 +7,9 @@ from dishka.integrations.fastapi import DishkaRoute, FromDishka
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["backfill"], route_class=DishkaRoute)
|
||||
from utils.jobs import enqueue
|
||||
|
||||
JOBS_CHANGED_CHANNEL = "jobs_changed"
|
||||
router = APIRouter(prefix="/api", tags=["backfill"], route_class=DishkaRoute)
|
||||
|
||||
|
||||
class BackfillRequest(BaseModel):
|
||||
@@ -52,25 +52,11 @@ def _to_view(row: asyncpg.Record) -> JobView:
|
||||
return JobView(**data)
|
||||
|
||||
|
||||
async def _enqueue(
|
||||
pool: asyncpg.Pool, account_id: int, kind: str, params: dict[str, Any]
|
||||
) -> int:
|
||||
job_id = await pool.fetchval(
|
||||
"INSERT INTO jobs (account_id, kind, params) "
|
||||
"VALUES ($1, $2, $3::jsonb) RETURNING id",
|
||||
account_id,
|
||||
kind,
|
||||
json.dumps(params),
|
||||
)
|
||||
await pool.execute(f"NOTIFY {JOBS_CHANGED_CHANNEL}")
|
||||
return job_id
|
||||
|
||||
|
||||
@router.post("/backfill", status_code=201)
|
||||
async def enqueue_backfill(
|
||||
pool: FromDishka[asyncpg.Pool], body: BackfillRequest
|
||||
) -> EnqueueResponse:
|
||||
job_id = await _enqueue(
|
||||
job_id = await enqueue(
|
||||
pool,
|
||||
body.account_id,
|
||||
"backfill",
|
||||
@@ -83,7 +69,7 @@ async def enqueue_backfill(
|
||||
async def enqueue_fetch_media(
|
||||
pool: FromDishka[asyncpg.Pool], body: FetchMediaRequest
|
||||
) -> EnqueueResponse:
|
||||
job_id = await _enqueue(
|
||||
job_id = await enqueue(
|
||||
pool,
|
||||
body.account_id,
|
||||
"fetch_media",
|
||||
|
||||
Reference in New Issue
Block a user