Services: - api: FastAPI gateway with JWT auth, async endpoints, WebSocket - worker-gpu: CUDA sentence-transformers, FAISS IVFFlat, Ollama LLM - worker-indexer: Winnowing+MinHash plagiarism detection, PDF/DOCX extraction - worker-notifier: SMTP email notifications - worker-gost: GOST 7.1-2003 and GOST R 7.0.5-2008 formatting Infrastructure: - docker-compose.yml (production) + docker-compose.dev.yml (hot reload) - Nginx reverse proxy + WebSocket support - PostgreSQL 16 with Alembic migrations - Elasticsearch 8 with Russian/English analyzers - MinIO, RabbitMQ, Redis, Ollama Frontend: - React 18 + Vite + TypeScript + TailwindCSS + Zustand + React Query v5 - 9 pages: Home, Search, Cabinet, Task, Check, Bibliography, Pricing, Login, Register Scripts: - Parser stubs: OpenAlex, КиберЛенинка, arXiv (Phase 0 - to be filled) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
"""Синхронное подключение к PostgreSQL и MinIO для индексер-воркера."""
|
|
|
|
import logging
|
|
from contextlib import contextmanager
|
|
from typing import Generator
|
|
|
|
from minio import Minio
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import Session, sessionmaker
|
|
|
|
from app.config import settings
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Синхронный движок SQLAlchemy
|
|
engine = create_engine(
|
|
settings.database_url_sync,
|
|
pool_size=5,
|
|
max_overflow=10,
|
|
pool_pre_ping=True,
|
|
pool_recycle=3600,
|
|
)
|
|
|
|
SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False)
|
|
|
|
|
|
@contextmanager
|
|
def db_session() -> Generator[Session, None, None]:
|
|
"""Контекстный менеджер для сессии БД."""
|
|
session = SessionLocal()
|
|
try:
|
|
yield session
|
|
session.commit()
|
|
except Exception:
|
|
session.rollback()
|
|
raise
|
|
finally:
|
|
session.close()
|
|
|
|
|
|
_minio_client: Minio | None = None
|
|
|
|
|
|
def get_minio() -> Minio:
|
|
"""Получить или создать MinIO клиент."""
|
|
global _minio_client
|
|
if _minio_client is None:
|
|
_minio_client = Minio(
|
|
settings.MINIO_ENDPOINT,
|
|
access_key=settings.MINIO_ACCESS_KEY,
|
|
secret_key=settings.MINIO_SECRET_KEY,
|
|
secure=False,
|
|
)
|
|
return _minio_client
|
|
|
|
|
|
def update_task_status(task_id: str, status: str, error: str | None = None) -> None:
|
|
"""Обновить статус задачи в БД."""
|
|
from app.models import Task
|
|
|
|
with db_session() as session:
|
|
task = session.get(Task, task_id)
|
|
if task:
|
|
task.status = status
|
|
if error:
|
|
task.error = error
|
|
session.commit()
|