Spaces:
Running
Running
from fastapi import FastAPI, HTTPException | |
from fastapi.middleware.cors import CORSMiddleware | |
from loguru import logger | |
import uvicorn | |
from services.database_service import db_service | |
from services.queue_service import queue_service | |
from api.routes import document_routes, ai_routes, test_routes, automation_routes | |
app = FastAPI( | |
title="AI-Powered Test Automation Framework", | |
description="An intelligent test automation framework powered by AI", | |
version="1.0.0" | |
) | |
# Add CORS middleware | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
# Include routers | |
app.include_router(document_routes.router, prefix="/api/documents", tags=["Documents"]) | |
app.include_router(ai_routes.router, prefix="/api/ai", tags=["AI"]) | |
app.include_router(test_routes.router, prefix="/api/tests", tags=["Tests"]) | |
app.include_router(automation_routes.router, prefix="/api/automation", tags=["Automation"]) | |
async def startup_event(): | |
"""Initialize services on startup""" | |
try: | |
# Initialize database | |
db_service.init_db() | |
logger.info("Database initialized successfully") | |
# Initialize queue service | |
queue_service.connect() | |
logger.info("Queue service initialized successfully") | |
except Exception as e: | |
logger.error(f"Error during startup: {str(e)}") | |
raise | |
async def shutdown_event(): | |
"""Cleanup on shutdown""" | |
try: | |
queue_service.close() | |
logger.info("Services shut down successfully") | |
except Exception as e: | |
logger.error(f"Error during shutdown: {str(e)}") | |
async def health_check(): | |
"""Health check endpoint""" | |
return {"status": "healthy"} | |
if __name__ == "__main__": | |
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |