fix: prune data and system before starting

This commit is contained in:
Boris Arzentar 2024-10-01 12:45:24 +02:00
parent d79017b09d
commit 3e88a314d8

View file

@ -35,6 +35,12 @@ async def lifespan(app: FastAPI):
from cognee.infrastructure.databases.relational import create_db_and_tables
# Not needed if you setup a migration system like Alembic
import asyncio
from cognee.modules.data.deletion import prune_system, prune_data
asyncio.run(prune_data())
asyncio.run(prune_system(metadata = True))
await create_db_and_tables()
yield
@ -388,11 +394,6 @@ def start_api_server(host: str = "0.0.0.0", port: int = 8000):
try:
logger.info("Starting server at %s:%s", host, port)
import asyncio
from cognee.modules.data.deletion import prune_system, prune_data
asyncio.run(prune_data())
asyncio.run(prune_system(metadata = True))
uvicorn.run(app, host = host, port = port)
except Exception as e:
logger.exception(f"Failed to start server: {e}")