Add ruff and mypy to dev dependencies with configuration in pyproject.toml. Add a lint CI job that runs ruff check, ruff format --check, and mypy. Auto-fix import sorting and formatting across the codebase. Exclude alembic/versions from linting (auto-generated migrations). Ignore B008 (FastAPI Depends pattern) and RUF001 (unicode in user-facing strings). 21 ruff lint errors and 50 mypy errors remain for manual review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.logging_utils import structured_log
|
|
from app.services.domains.publications.pdf_queue import (
|
|
enqueue_missing_pdf_jobs,
|
|
enqueue_retry_pdf_job,
|
|
overlay_pdf_job_state,
|
|
)
|
|
from app.services.domains.publications.types import PublicationListItem
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def schedule_missing_pdf_enrichment_for_user(
|
|
db_session: AsyncSession,
|
|
*,
|
|
user_id: int,
|
|
request_email: str | None,
|
|
items: list[PublicationListItem],
|
|
max_items: int,
|
|
) -> int:
|
|
queued_ids = await enqueue_missing_pdf_jobs(
|
|
db_session,
|
|
user_id=user_id,
|
|
request_email=request_email,
|
|
rows=items,
|
|
max_items=max_items,
|
|
)
|
|
structured_log(
|
|
logger, "info", "publications.enrichment.scheduled", user_id=user_id, publication_count=len(queued_ids)
|
|
)
|
|
return len(queued_ids)
|
|
|
|
|
|
async def schedule_retry_pdf_enrichment_for_row(
|
|
db_session: AsyncSession,
|
|
*,
|
|
user_id: int,
|
|
request_email: str | None,
|
|
item: PublicationListItem,
|
|
) -> bool:
|
|
queued = await enqueue_retry_pdf_job(
|
|
db_session,
|
|
user_id=user_id,
|
|
request_email=request_email,
|
|
row=item,
|
|
)
|
|
structured_log(
|
|
logger,
|
|
"info",
|
|
"publications.enrichment.retry_scheduled",
|
|
user_id=user_id,
|
|
publication_id=item.publication_id,
|
|
queued=queued,
|
|
)
|
|
return queued
|
|
|
|
|
|
async def hydrate_pdf_enrichment_state(
|
|
db_session: AsyncSession,
|
|
*,
|
|
items: list[PublicationListItem],
|
|
) -> list[PublicationListItem]:
|
|
return await overlay_pdf_job_state(db_session, rows=items)
|