major claude changes
This commit is contained in:
46
main.py
46
main.py
@@ -1,11 +1,39 @@
|
||||
import logging
|
||||
import sys
|
||||
from fastapi import FastAPI
|
||||
from app.routers import delivery
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from config import load_config
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
ApplicationConfig = load_config()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
handlers=[logging.StreamHandler(sys.stdout)]
|
||||
)
|
||||
logger = logging.getLogger('eamco_money_api')
|
||||
|
||||
# Database setup
|
||||
engine = create_engine(ApplicationConfig.SQLALCHEMY_DATABASE_URI)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
def check_db_connection():
|
||||
"""
|
||||
Test database connectivity.
|
||||
"""
|
||||
try:
|
||||
db = SessionLocal()
|
||||
db.execute(text("SELECT 1"))
|
||||
db.close()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -23,3 +51,21 @@ app.add_middleware(
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Status": "Money Service is online"}
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""Application startup - log configuration and test DB connection."""
|
||||
logger.info("🚀 eamco_money_api STARTING")
|
||||
mode = ApplicationConfig.CURRENT_SETTINGS.upper()
|
||||
if mode in ['DEVELOPMENT', 'DEV']:
|
||||
logger.info("🤖🤖🤖🤖🤖 Mode: Development 🤖🤖🤖🤖🤖")
|
||||
elif mode in ['PRODUCTION', 'PROD']:
|
||||
logger.info("💀💀💀💀💀💀💀💀💀💀 ⚠️ WARNING PRODUCTION 💀💀💀💀💀💀💀💀💀💀")
|
||||
logger.info(f"DB: {ApplicationConfig.SQLALCHEMY_DATABASE_URI[:30]}...")
|
||||
logger.info(f"CORS: {len(ApplicationConfig.origins)} origins configured")
|
||||
|
||||
# Test database connection
|
||||
if check_db_connection():
|
||||
logger.info("DB Connection: ✅ OK")
|
||||
else:
|
||||
logger.info("DB Connection: ❌ FAILED")
|
||||
|
||||
Reference in New Issue
Block a user