- gateway: separate config, models, state, audit, guardrail, embeddings, store, metrics, cleanup and routes; keep main.py as FastAPI bootstrap - extension: split client/config, six tools, config command and rules; preserve jiti entrypoint and registrations - Dockerfile copies the complete gateway module set - tests: update monkeypatch boundaries for modular config/state
29 lines
995 B
Python
29 lines
995 B
Python
"""Pulizia periodica dei record scaduti."""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from typing import Any, Callable
|
|
|
|
from qdrant_client.http import models as qm
|
|
|
|
from config import log
|
|
|
|
|
|
async def loop(qdrant: Any, collection: str, invalidate_meta: Callable[[], None]) -> None:
|
|
while True:
|
|
try:
|
|
scroll = qdrant.scroll(
|
|
collection_name=collection,
|
|
scroll_filter=qm.Filter(must=[qm.FieldCondition(key="expires_at", range=qm.Range(lt=time.time()))]),
|
|
limit=100,
|
|
with_payload=False,
|
|
)
|
|
ids = [point.id for point in scroll[0]]
|
|
if ids:
|
|
qdrant.delete(collection_name=collection, points_selector=ids)
|
|
invalidate_meta()
|
|
log.info("cleanup: rimossi %d record scaduti", len(ids))
|
|
except Exception as exc: # noqa: BLE001
|
|
log.warning("cleanup error: %s", exc)
|
|
await __import__("asyncio").sleep(3600)
|