-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (68 loc) · 2.42 KB
/
main.py
File metadata and controls
88 lines (68 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
NASDAQ Stock Agent - Main Application Entry Point
"""
import logging
import uvicorn
from src.api.app import create_app
from src.core.config_manager import config_manager
from src.core.dependencies import service_container
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def main():
"""Main application entry point"""
try:
# Load configuration
config = config_manager.load_configuration()
app_config = config.get("application", {})
# Create FastAPI application
app = create_app()
logger.info(f"Starting {app_config.get('name', 'NASDAQ Stock Agent')} v{app_config.get('version', '1.0.0')}")
return app
except Exception as e:
logger.error(f"Failed to start application: {e}")
raise
async def startup_check():
"""Perform startup health check"""
try:
logger.info("Performing startup health check...")
# Initialize services
await service_container.initialize()
# Get system status
status = await service_container.get_system_status()
if status.get('status') in ['healthy', 'degraded']:
logger.info("Startup health check passed")
return True
else:
logger.error(f"Startup health check failed: {status}")
return False
except Exception as e:
logger.error(f"Startup health check error: {e}")
return False
if __name__ == "__main__":
try:
# Load configuration
config = config_manager.load_configuration()
app_config = config.get("application", {})
# Get server configuration
host = app_config.get("host", "0.0.0.0")
port = app_config.get("port", 8000)
debug = app_config.get("debug", False)
logger.info(f"Starting server on {host}:{port} (debug={debug})")
# Run server
uvicorn.run(
"main:main",
host=host,
port=port,
reload=debug,
factory=True,
log_level="info" if not debug else "debug"
)
except KeyboardInterrupt:
logger.info("Application stopped by user")
except Exception as e:
logger.error(f"Application startup failed: {e}")
exit(1)