Add Telegram listener, scheduler, and extended parsers admin UI.
Introduce background scheduling and migrations for analytics ingest, expand parser management and map toolbar UX, and ignore local data/session files from version control. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -14,6 +14,7 @@ from ..schemas import (
|
||||
EventRead,
|
||||
ParseJobCreate,
|
||||
ParseJobRead,
|
||||
ParseJobUpdate,
|
||||
TimelinePoint,
|
||||
TopItem,
|
||||
)
|
||||
@@ -42,6 +43,8 @@ def create_parse_job(payload: ParseJobCreate, db: Session = Depends(get_db)):
|
||||
source_type=payload.source_type,
|
||||
source_config=payload.source_config,
|
||||
schedule=payload.schedule,
|
||||
interval_seconds=payload.interval_seconds,
|
||||
is_active=payload.is_active,
|
||||
status="queued",
|
||||
)
|
||||
db.add(job)
|
||||
@@ -70,6 +73,8 @@ def retry_parse_job(job_id: int, 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")
|
||||
if job.status in ("queued", "running"):
|
||||
raise HTTPException(status_code=409, detail="Job is already running or queued")
|
||||
|
||||
job.status = "queued"
|
||||
job.last_error = None
|
||||
@@ -80,6 +85,40 @@ def retry_parse_job(job_id: int, db: Session = Depends(get_db)):
|
||||
return job
|
||||
|
||||
|
||||
@router.patch("/jobs/{job_id}", response_model=ParseJobRead)
|
||||
def update_parse_job(
|
||||
job_id: int,
|
||||
payload: ParseJobUpdate,
|
||||
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")
|
||||
|
||||
if payload.source_config is not None:
|
||||
job.source_config = payload.source_config
|
||||
if payload.interval_seconds is not None:
|
||||
job.interval_seconds = payload.interval_seconds
|
||||
if payload.is_active is not None:
|
||||
job.is_active = payload.is_active
|
||||
|
||||
db.commit()
|
||||
db.refresh(job)
|
||||
return job
|
||||
|
||||
|
||||
@router.delete("/jobs/{job_id}", status_code=204)
|
||||
def delete_parse_job(job_id: int, 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")
|
||||
if job.status == "running":
|
||||
raise HTTPException(status_code=409, detail="Cannot delete a running job")
|
||||
|
||||
db.delete(job)
|
||||
db.commit()
|
||||
|
||||
|
||||
@router.get("/events", response_model=EventListResponse)
|
||||
def list_events(
|
||||
limit: int = Query(default=50, ge=1, le=1000),
|
||||
|
||||
@@ -6,7 +6,7 @@ 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 ..schemas import IngestRequest, IngestResponse, ListenerSubscription
|
||||
from ..services.ingest import ingest_events
|
||||
|
||||
router = APIRouter(prefix="/internal", tags=["internal"])
|
||||
@@ -18,10 +18,16 @@ def internal_ingest(
|
||||
_: None = Depends(verify_internal_token),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
ingested, updated, map_synced = ingest_events(db, payload.events, payload.job_id)
|
||||
ingested, updated, skipped, map_synced = ingest_events(
|
||||
db,
|
||||
payload.events,
|
||||
payload.job_id,
|
||||
touch_job=not payload.listener,
|
||||
)
|
||||
return IngestResponse(
|
||||
ingested=ingested,
|
||||
updated=updated,
|
||||
skipped=skipped,
|
||||
map_objects_synced=map_synced,
|
||||
)
|
||||
|
||||
@@ -39,7 +45,31 @@ def update_job_status(
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
||||
job.status = status
|
||||
job.last_run_at = datetime.now(timezone.utc)
|
||||
if status in ("completed", "failed"):
|
||||
job.last_run_at = datetime.now(timezone.utc)
|
||||
job.last_error = error
|
||||
db.commit()
|
||||
return {"id": job.id, "status": job.status}
|
||||
|
||||
|
||||
@router.get("/listener/subscriptions", response_model=list[ListenerSubscription])
|
||||
def listener_subscriptions(
|
||||
_: None = Depends(verify_internal_token),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
jobs = (
|
||||
db.query(ParseJob)
|
||||
.filter(
|
||||
ParseJob.is_active.is_(True),
|
||||
ParseJob.source_type == "telegram",
|
||||
)
|
||||
.order_by(ParseJob.id.asc())
|
||||
.all()
|
||||
)
|
||||
result: list[ListenerSubscription] = []
|
||||
for job in jobs:
|
||||
channel = job.source_config.get("channel") if job.source_config else None
|
||||
if not channel:
|
||||
continue
|
||||
result.append(ListenerSubscription(job_id=job.id, channel=str(channel)))
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user