task_app.py 931 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import logging
  2. from quart_cors import cors
  3. from quart import Quart
  4. from app.core.bootstrap import AppContext
  5. from app.core.dependency import ServerContainer
  6. from app.api.v1.routes import server_routes
  7. logging.basicConfig(level=logging.INFO)
  8. app = Quart(__name__)
  9. app = cors(app, allow_origin="*")
  10. server_container = ServerContainer()
  11. ctx = AppContext(server_container)
  12. config = server_container.config()
  13. log_service = server_container.log_service()
  14. mysql_manager = server_container.mysql_manager()
  15. routes = server_routes(mysql_manager, log_service, config)
  16. app.register_blueprint(routes)
  17. @app.before_serving
  18. async def startup():
  19. logging.info("Starting application...")
  20. await ctx.start_up()
  21. logging.info("Application started successfully")
  22. @app.after_serving
  23. async def shutdown():
  24. logging.info("Shutting down application...")
  25. await ctx.shutdown()
  26. logging.info("Application shutdown successfully")