Refactoring config to config_upload, making important vars global
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
from src.config.router import router as config_router
|
||||
|
||||
__all__ = ["config_router"]
|
||||
@@ -1,2 +0,0 @@
|
||||
# contains the business logic for the config service
|
||||
async def save_config() -> None: ...
|
||||
3
src/config_upload/__init__.py
Normal file
3
src/config_upload/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from src.config_upload.router import router as config_router
|
||||
|
||||
__all__ = ["config_router"]
|
||||
@@ -3,10 +3,12 @@ import logging
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .schema import ConfigReturnSchema, ConfigSchema
|
||||
from src.database import get_config_from_db
|
||||
from src.main import shared_redis_conn
|
||||
|
||||
logger = logging.getLogger("uvicorn")
|
||||
|
||||
router = APIRouter(tags=["config"])
|
||||
router = APIRouter(tags=["config_upload"])
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -20,3 +22,4 @@ async def create_config(config: ConfigSchema) -> ConfigSchema:
|
||||
"""
|
||||
logger.info("Received configuration data")
|
||||
return config
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# contains the schema definitions for the config service
|
||||
# contains the schema definitions for the config_upload service
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
2
src/config_upload/service.py
Normal file
2
src/config_upload/service.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# contains the business logic for the config_upload service
|
||||
async def save_config() -> None: ...
|
||||
11
src/main.py
11
src/main.py
@@ -3,8 +3,11 @@ import logging
|
||||
import httpx
|
||||
from fastapi import FastAPI
|
||||
|
||||
shared_redis_conn = None
|
||||
requests_client = None
|
||||
|
||||
from src.aggregate import aggregate_router
|
||||
from src.config import config_router
|
||||
from src.config_upload import config_router
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
@@ -17,9 +20,11 @@ logger.setLevel("DEBUG")
|
||||
logger.info("Starting application")
|
||||
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""make loading it async"""
|
||||
global shared_redis_conn, requests_client
|
||||
log = logging.getLogger("uvicorn")
|
||||
cfg_init_result = initialize_config()
|
||||
|
||||
@@ -33,9 +38,9 @@ async def lifespan(app: FastAPI):
|
||||
if not cfg_init_result:
|
||||
log.error("Configuration initialization failed. Exiting...")
|
||||
# exit(1)
|
||||
app.requests_client = httpx.AsyncClient(verify=False)
|
||||
requests_client = httpx.AsyncClient(verify=False)
|
||||
yield
|
||||
await app.requests_client.aclose()
|
||||
await requests_client.aclose()
|
||||
log.info("Shutting down FastAPI app...")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user