refactor: Pydantic webhook payload models, lifespan task cancellation, dict/Pydantic compat helpers

This commit is contained in:
Marker689
2026-05-11 22:07:35 +03:00
parent 6e3c2c5caa
commit 3f44de1d98
3 changed files with 66 additions and 27 deletions

View File

@@ -55,19 +55,26 @@ class LangMiddleware(BaseHTTPMiddleware):
async def lifespan(app: FastAPI):
await init_db()
log.info("%s started on %s:%s", APP_NAME, config.host, config.port)
# Start background lock cleanup tasks
asyncio.create_task(_start_lock_cleanup())
tasks = [
asyncio.create_task(_cleanup_url_locks()),
asyncio.create_task(_cleanup_llm_locks()),
]
yield
for t in tasks:
t.cancel()
log.info("%s shutting down", APP_NAME)
async def _start_lock_cleanup():
"""Start background tasks for cleanup of unused locks."""
from guarddog_nexus.core.harvester import _cleanup_url_locks
from guarddog_nexus.routes.web import _cleanup_llm_locks
async def _cleanup_url_locks():
from guarddog_nexus.core.harvester import _cleanup_url_locks as _fn
asyncio.create_task(_cleanup_url_locks())
asyncio.create_task(_cleanup_llm_locks())
await _fn()
async def _cleanup_llm_locks():
from guarddog_nexus.routes.web import _cleanup_llm_locks as _fn
await _fn()
class RequestLoggingMiddleware(BaseHTTPMiddleware):