generated from coulomb/repo-seed
structured logging around key workflows and docs for operational readiness
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import asdict
|
||||
from pathlib import Path
|
||||
|
||||
@@ -62,6 +63,7 @@ class Settings(BaseSettings):
|
||||
llm_provider: str | None = Field(default=None)
|
||||
llm_model: str | None = Field(default=None)
|
||||
embedding_provider: str | None = Field(default=None)
|
||||
log_level: str = Field(default="INFO")
|
||||
|
||||
|
||||
def get_settings() -> Settings:
|
||||
@@ -69,6 +71,9 @@ def get_settings() -> Settings:
|
||||
|
||||
|
||||
def get_service(settings: Settings = Depends(get_settings)) -> RegistryService:
|
||||
logging.getLogger("repo_registry.operations").setLevel(
|
||||
getattr(logging, settings.log_level.upper(), logging.INFO)
|
||||
)
|
||||
database_path = Path(settings.database_path)
|
||||
database_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
store = RegistryStore(database_path)
|
||||
@@ -120,8 +125,33 @@ app.include_router(ui_router)
|
||||
|
||||
|
||||
@app.get("/health", tags=["health"])
|
||||
def health() -> dict[str, str]:
|
||||
return {"status": "ok"}
|
||||
def health(settings: Settings = Depends(get_settings)) -> dict[str, object]:
|
||||
database_path = Path(settings.database_path)
|
||||
checkout_root = Path(settings.checkout_root)
|
||||
database_reachable = False
|
||||
database_error = None
|
||||
try:
|
||||
database_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
store = RegistryStore(database_path)
|
||||
store.initialize()
|
||||
with store.connect() as connection:
|
||||
connection.execute("SELECT 1").fetchone()
|
||||
database_reachable = True
|
||||
except Exception as exc:
|
||||
database_error = str(exc)
|
||||
|
||||
return {
|
||||
"status": "ok" if database_reachable else "degraded",
|
||||
"database": {
|
||||
"path": str(database_path),
|
||||
"reachable": database_reachable,
|
||||
"error": database_error,
|
||||
},
|
||||
"checkout_root": {
|
||||
"path": str(checkout_root),
|
||||
"exists": checkout_root.exists(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@app.post(
|
||||
|
||||
Reference in New Issue
Block a user