thechaiexperiment commited on
Commit
199bbdc
·
verified ·
1 Parent(s): 7aaf8ef

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +61 -61
app/main.py CHANGED
@@ -1,61 +1,61 @@
1
- from fastapi import FastAPI, HTTPException
2
- from fastapi.middleware.cors import CORSMiddleware
3
- from loguru import logger
4
- import uvicorn
5
-
6
- from services.database_service import db_service
7
- from services.queue_service import queue_service
8
- from api.routes import document_routes, ai_routes, test_routes, automation_routes
9
-
10
- app = FastAPI(
11
- title="AI-Powered Test Automation Framework",
12
- description="An intelligent test automation framework powered by AI",
13
- version="1.0.0"
14
- )
15
-
16
- # Add CORS middleware
17
- app.add_middleware(
18
- CORSMiddleware,
19
- allow_origins=["*"],
20
- allow_credentials=True,
21
- allow_methods=["*"],
22
- allow_headers=["*"],
23
- )
24
-
25
- # Include routers
26
- app.include_router(document_routes.router, prefix="/api/documents", tags=["Documents"])
27
- app.include_router(ai_routes.router, prefix="/api/ai", tags=["AI"])
28
- app.include_router(test_routes.router, prefix="/api/tests", tags=["Tests"])
29
- app.include_router(automation_routes.router, prefix="/api/automation", tags=["Automation"])
30
-
31
- @app.on_event("startup")
32
- async def startup_event():
33
- """Initialize services on startup"""
34
- try:
35
- # Initialize database
36
- db_service.init_db()
37
- logger.info("Database initialized successfully")
38
-
39
- # Initialize queue service
40
- queue_service.connect()
41
- logger.info("Queue service initialized successfully")
42
- except Exception as e:
43
- logger.error(f"Error during startup: {str(e)}")
44
- raise
45
-
46
- @app.on_event("shutdown")
47
- async def shutdown_event():
48
- """Cleanup on shutdown"""
49
- try:
50
- queue_service.close()
51
- logger.info("Services shut down successfully")
52
- except Exception as e:
53
- logger.error(f"Error during shutdown: {str(e)}")
54
-
55
- @app.get("/health")
56
- async def health_check():
57
- """Health check endpoint"""
58
- return {"status": "healthy"}
59
-
60
- if __name__ == "__main__":
61
- uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from loguru import logger
4
+ import uvicorn
5
+
6
+ from services.database_service import db_service
7
+ from services.queue_service import queue_service
8
+ from api.routes import document_routes, ai_routes, test_routes, automation_routes
9
+
10
+ app = FastAPI(
11
+ title="AI-Powered Test Automation Framework",
12
+ description="An intelligent test automation framework powered by AI",
13
+ version="1.0.0"
14
+ )
15
+
16
+ # Add CORS middleware
17
+ app.add_middleware(
18
+ CORSMiddleware,
19
+ allow_origins=["*"],
20
+ allow_credentials=True,
21
+ allow_methods=["*"],
22
+ allow_headers=["*"],
23
+ )
24
+
25
+ # Include routers
26
+ app.include_router(document_routes.router, prefix="/api/documents", tags=["Documents"])
27
+ app.include_router(ai_routes.router, prefix="/api/ai", tags=["AI"])
28
+ app.include_router(test_routes.router, prefix="/api/tests", tags=["Tests"])
29
+ app.include_router(automation_routes.router, prefix="/api/automation", tags=["Automation"])
30
+
31
+ @app.on_event("startup")
32
+ async def startup_event():
33
+ """Initialize services on startup"""
34
+ try:
35
+ # Initialize database
36
+ db_service.init_db()
37
+ logger.info("Database initialized successfully")
38
+
39
+ # Initialize queue service
40
+ queue_service.connect()
41
+ logger.info("Queue service initialized successfully")
42
+ except Exception as e:
43
+ logger.error(f"Error during startup: {str(e)}")
44
+ raise
45
+
46
+ @app.on_event("shutdown")
47
+ async def shutdown_event():
48
+ """Cleanup on shutdown"""
49
+ try:
50
+ queue_service.close()
51
+ logger.info("Services shut down successfully")
52
+ except Exception as e:
53
+ logger.error(f"Error during shutdown: {str(e)}")
54
+
55
+ @app.get("/health")
56
+ async def health_check():
57
+ """Health check endpoint"""
58
+ return {"status": "healthy"}
59
+
60
+ if __name__ == "__main__":
61
+ uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)