Skip to content

Commit

Permalink
fix: use lifespan
Browse files Browse the repository at this point in the history
fix: readd vocabularies endpoint
  • Loading branch information
xgui3783 committed Aug 29, 2024
1 parent eef3c7d commit 019fc53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions api/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fastapi_pagination import add_pagination
from fastapi_versioning import VersionedFastAPI
from pathlib import Path
from contextlib import asynccontextmanager

import time
import json
Expand All @@ -20,6 +21,7 @@
from .volumes import prefixed_routers as volume_prefixed_routers
from .compounds import prefixed_routers as compound_prefixed_routers
from .features import router as feature_router
from .volcabularies import router as vocabularies_router
from .metrics import prom_metrics_resp, on_startup as metrics_on_startup, on_terminate as metrics_on_terminate
from .code_snippet import get_sourcecode

Expand All @@ -28,16 +30,26 @@

siibra_version_header = "x-siibra-api-version"

@asynccontextmanager
async def lifespan():
on_startup()
metrics_on_startup()
yield
terminate()
metrics_on_terminate()

siibra_api = FastAPI(
title="siibra api",
description="This is the REST api for siibra tools",
version=__version__,
lifespan=lifespan,
)

for prefix_router in [*core_prefixed_routers, *volume_prefixed_routers, *compound_prefixed_routers]:
siibra_api.include_router(prefix_router.router, prefix=prefix_router.prefix)

siibra_api.include_router(feature_router, prefix="/feature")
siibra_api.include_router(vocabularies_router, prefix="/vocabularies")

add_pagination(siibra_api)

Expand Down Expand Up @@ -356,17 +368,6 @@ async def exception_other(request: Request, exc: Exception):
}
)

@siibra_api.on_event("shutdown")
def shutdown():
"""On shutdown"""
terminate()
metrics_on_terminate()

@siibra_api.on_event("startup")
def startup():
"""On startup"""
on_startup()
metrics_on_startup()

import logging
class EndpointLoggingFilter(logging.Filter):
Expand Down
2 changes: 1 addition & 1 deletion api/server/volcabularies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@router.get("/genes", response_model=Page[GeneModel])
@version(*FASTAPI_VERSION)
@router_decorator(ROLE, func=get_genes)
def get_genes(find:str=None, func=None):
def genes(find:str=None, func=None):
"""HTTP get (filtered) genes"""
if func is None:
raise HTTPException(500, "func: None passed")
Expand Down

0 comments on commit 019fc53

Please sign in to comment.