Unify parsing workers, analytics API with PostgreSQL, map UI, and PI distribution into centers/ with Docker Compose. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ..database import get_db
|
|
from ..deps import verify_internal_token
|
|
from ..models import ParseJob
|
|
from ..schemas import IngestRequest, IngestResponse
|
|
from ..services.ingest import ingest_events
|
|
|
|
router = APIRouter(prefix="/internal", tags=["internal"])
|
|
|
|
|
|
@router.post("/ingest", response_model=IngestResponse)
|
|
def internal_ingest(
|
|
payload: IngestRequest,
|
|
_: None = Depends(verify_internal_token),
|
|
db: Session = Depends(get_db),
|
|
):
|
|
ingested, updated, map_synced = ingest_events(db, payload.events, payload.job_id)
|
|
return IngestResponse(
|
|
ingested=ingested,
|
|
updated=updated,
|
|
map_objects_synced=map_synced,
|
|
)
|
|
|
|
|
|
@router.patch("/jobs/{job_id}")
|
|
def update_job_status(
|
|
job_id: int,
|
|
status: str,
|
|
error: str | None = None,
|
|
_: None = Depends(verify_internal_token),
|
|
db: Session = Depends(get_db),
|
|
):
|
|
job = db.query(ParseJob).filter(ParseJob.id == job_id).first()
|
|
if not job:
|
|
raise HTTPException(status_code=404, detail="Job not found")
|
|
|
|
job.status = status
|
|
job.last_run_at = datetime.now(timezone.utc)
|
|
job.last_error = error
|
|
db.commit()
|
|
return {"id": job.id, "status": job.status}
|