From 8d4f30019b388ca061b955aad845d1e678674af7 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 7 Jun 2026 15:47:03 +0200 Subject: [PATCH] feat(nlp-service): log WARNING when DATABASE_URL absent, ERROR on DB failure Co-Authored-By: Claude Sonnet 4.6 --- nlp-service/main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nlp-service/main.py b/nlp-service/main.py index 3894cca0..52533188 100644 --- a/nlp-service/main.py +++ b/nlp-service/main.py @@ -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