Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close engine connection at the end of the lifespan and patch logger #6

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions labs_api/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import typing as t
from contextlib import asynccontextmanager

import fastapi
import uvicorn
from config import Config
from fastapi.middleware.cors import CORSMiddleware
from prediction_market_agent_tooling.gtypes import HexAddress
from prediction_market_agent_tooling.loggers import logger
from prediction_market_agent_tooling.loggers import logger, patch_logger

from labs_api.config import Config
from labs_api.insights import MarketInsightsResponse, market_insights_cached
Expand All @@ -22,7 +23,16 @@


def create_app() -> fastapi.FastAPI:
app = fastapi.FastAPI()
patch_logger()

@asynccontextmanager
async def lifespan(app: fastapi.FastAPI) -> t.AsyncIterator[None]:
# At start of the service.
yield
# At end of the service.
market_insights_cache.engine.dispose()

app = fastapi.FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Expand Down
Loading