feat: add FastAPI lifespan and healthcheck endpoint (#144)
* chore: Add healthcheck endpoint + build indexes and constraints on svc startup * chore: Bring back driver close call
This commit is contained in:
parent
5d2121e1a3
commit
2fc1b00602
3 changed files with 29 additions and 5 deletions
|
|
@ -158,8 +158,8 @@ class Graphiti:
|
||||||
# Use graphiti...
|
# Use graphiti...
|
||||||
finally:
|
finally:
|
||||||
graphiti.close()
|
graphiti.close()
|
||||||
self.driver.close()
|
|
||||||
"""
|
"""
|
||||||
|
self.driver.close()
|
||||||
|
|
||||||
async def build_indices_and_constraints(self):
|
async def build_indices_and_constraints(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,29 @@
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
|
from graph_service.config import get_settings
|
||||||
from graph_service.routers import ingest, retrieve
|
from graph_service.routers import ingest, retrieve
|
||||||
|
from graph_service.zep_graphiti import initialize_graphiti
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(_: FastAPI):
|
||||||
|
settings = get_settings()
|
||||||
|
await initialize_graphiti(settings)
|
||||||
|
yield
|
||||||
|
# Shutdown
|
||||||
|
# No need to close Graphiti here, as it's handled per-request
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
|
|
||||||
app.include_router(retrieve.router)
|
app.include_router(retrieve.router)
|
||||||
app.include_router(ingest.router)
|
app.include_router(ingest.router)
|
||||||
|
|
||||||
|
|
||||||
@app.get('/')
|
@app.get('/healthcheck')
|
||||||
def read_root():
|
async def healthcheck():
|
||||||
return {'Hello': 'World'}
|
return JSONResponse(content={'status': 'healthy'}, status_code=200)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,15 @@ async def get_graphiti(settings: ZepEnvDep):
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
|
||||||
|
async def initialize_graphiti(settings: ZepEnvDep):
|
||||||
|
client = ZepGraphiti(
|
||||||
|
uri=settings.neo4j_uri,
|
||||||
|
user=settings.neo4j_user,
|
||||||
|
password=settings.neo4j_password,
|
||||||
|
)
|
||||||
|
await client.build_indices_and_constraints()
|
||||||
|
|
||||||
|
|
||||||
def get_fact_result_from_edge(edge: EntityEdge):
|
def get_fact_result_from_edge(edge: EntityEdge):
|
||||||
return FactResult(
|
return FactResult(
|
||||||
uuid=edge.uuid,
|
uuid=edge.uuid,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue