import asyncio import logging from quart import Quart from aiomonitor import start_monitor from applications.config import aliyun_log_config from applications.database import mysql_manager from applications.service import LogService from routes import server_routes log_service = LogService(**aliyun_log_config) app = Quart(__name__) routes = server_routes(mysql_manager, log_service) app.register_blueprint(routes) logging.basicConfig(level=logging.INFO) _monitor = None @app.before_serving async def startup(): global _monitor loop = asyncio.get_event_loop() _monitor = start_monitor(loop=loop, host="127.0.0.1", port=50101) logging.info(f"Monitor started at {_monitor}") logging.info("Starting application...") await mysql_manager.init_pools() logging.info("Mysql pools init successfully") await log_service.start() logging.info("aliyun log service init successfully") @app.after_serving async def shutdown(): logging.info("Shutting down application...") await mysql_manager.close_pools() logging.info("Mysql pools close successfully") await log_service.stop() logging.info("aliyun log service stop successfully") if _monitor: _monitor.close() logging.info("Monitor stopped successfully")