feat(nlp-service): log WARNING when DATABASE_URL absent, ERROR on DB failure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
"""FastAPI app — /parse and /health endpoints."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from extractor import extract, get_person_matcher, set_person_matcher
|
||||
from models import ParseRequest, ParseResponse
|
||||
from person_matcher import PersonMatcher
|
||||
@@ -30,8 +33,14 @@ async def lifespan(app: FastAPI):
|
||||
m = PersonMatcher()
|
||||
db_url = os.environ.get("DATABASE_URL")
|
||||
if db_url:
|
||||
rows = _load_persons_from_db(db_url)
|
||||
m.load(rows)
|
||||
try:
|
||||
rows = _load_persons_from_db(db_url)
|
||||
m.load(rows)
|
||||
logger.info("PersonMatcher loaded %d name variants from DB", len(m))
|
||||
except Exception:
|
||||
logger.error("Failed to load persons from DB — person matching disabled", exc_info=True)
|
||||
else:
|
||||
logger.warning("DATABASE_URL not set — person matching disabled")
|
||||
set_person_matcher(m)
|
||||
yield
|
||||
|
||||
|
||||
Reference in New Issue
Block a user