use the uvicorn logger; also update dockerfile to run migrations as parto f startup instead of when starting uvicorn
This commit is contained in:
parent
684af9a040
commit
744fa7b8a7
4 changed files with 17 additions and 63 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import logging.config
|
||||
from pathlib import Path
|
||||
import queue
|
||||
from threading import Thread
|
||||
|
|
@ -15,7 +17,6 @@ from api.worker import (
|
|||
)
|
||||
from fastapi import Depends, FastAPI, HTTPException, Query
|
||||
from api.auth import User
|
||||
from logger import get_logger
|
||||
from models.listing import QueryParameters
|
||||
from repositories.listing_repository import ListingRepository
|
||||
from repositories.listing_repository import ListingRepository
|
||||
|
|
@ -26,20 +27,21 @@ from alembic import command
|
|||
from alembic.config import Config
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
logger = get_logger(__file__)
|
||||
logger = logging.getLogger("uvicorn")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
alembic_cfg = Config("./alembic.ini")
|
||||
logger.info("Running alembic migrations")
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
logger.info("Finished running alembic migrations")
|
||||
yield
|
||||
logger.warning("Shutting down")
|
||||
# @asynccontextmanager
|
||||
# async def lifespan(app: FastAPI):
|
||||
# alembic_cfg = Config("./alembic.ini")
|
||||
# logger.info("Running alembic migrations")
|
||||
# command.upgrade(alembic_cfg, "head")
|
||||
# logger.info("Finished running alembic migrations")
|
||||
# yield
|
||||
# logger.warning("Shutting down")
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
# app = FastAPI(lifespan=lifespan)
|
||||
app = FastAPI()
|
||||
|
||||
# Start worker thread
|
||||
WorkerManager(DumpListingsWorker()).start()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue