refactor: extract admin business logic to services, introduce job queue, add derived index helpers
- Move DB operations from routes/admin.py to services/admin.py (get_logs_context, query_summary_statuses, retry_failed, delete/reset operations) - Add services/jobs.py with Job/JobEvent-based async job queue (create_job, run_job, enqueue_job) - Add services/derived.py with FTS5 reindex and paper index deletion helpers - Refactor scheduler to use job queue instead of direct pipeline calls - Add heartbeat_at/expires_at to TaskLock for lock health tracking - Remove DESIGN_REVIEW.md - Update tests: remove redundant integration tests, add unit tests for new services
This commit is contained in:
+3
-16
@@ -4,7 +4,7 @@ import logging
|
||||
from datetime import date as date_type, datetime, timezone
|
||||
|
||||
import httpx
|
||||
from sqlalchemy import select, text
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.config import settings
|
||||
@@ -16,6 +16,7 @@ from app.models import (
|
||||
SummaryState,
|
||||
SummaryStatus,
|
||||
)
|
||||
from app.services.derived import reindex_paper_fts
|
||||
from app.utils import make_http_client, recent_date_strs, utc_now
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -143,21 +144,7 @@ def upsert_papers(db: Session, papers_raw: list[dict], paper_date: str) -> list[
|
||||
|
||||
db.add(SummaryStatus(paper_id=paper.id, status=SummaryState.PENDING))
|
||||
|
||||
authors_text = ", ".join(meta["authors"])
|
||||
tags_text = ", ".join(meta["tags"])
|
||||
db.execute(
|
||||
text(
|
||||
"INSERT INTO papers_fts(rowid, title_en, abstract, authors, tags) "
|
||||
"VALUES (:id, :title, :abstract, :authors, :tags)"
|
||||
),
|
||||
{
|
||||
"id": paper.id,
|
||||
"title": meta["title_en"],
|
||||
"abstract": meta["abstract"] or "",
|
||||
"authors": authors_text,
|
||||
"tags": tags_text,
|
||||
},
|
||||
)
|
||||
reindex_paper_fts(db, paper)
|
||||
|
||||
new_papers.append(paper)
|
||||
logger.debug("Inserted new paper: %s", arxiv_id)
|
||||
|
||||
Reference in New Issue
Block a user