(api: FastAPI)
| 34 | |
| 35 | @asynccontextmanager |
| 36 | async def lifespan(api: FastAPI) -> AsyncGenerator[None]: |
| 37 | container = Container() |
| 38 | await container.rmq_producer().initialize() |
| 39 | await container.ws_service().worker_start() |
| 40 | AuthController(app=api, container=container) |
| 41 | UserController(app=api, container=container) |
| 42 | UserNotificationController(app=api, container=container) |
| 43 | WSController(app=api, container=container) |
| 44 | OptimizedWSController(app=api, container=container) |
| 45 | |
| 46 | for route in api.routes: |
| 47 | if hasattr(route, "methods"): # HTTP |
| 48 | methods = ",".join(route.methods) |
| 49 | print(f"HTTP {methods:<10} {route.path}") |
| 50 | elif route.__class__.__name__ == "APIWebSocketRoute": |
| 51 | print(f"WS {'-':<10} {route.path}") |
| 52 | else: |
| 53 | print(f"UNKNOWN {'-':<10} {route.path}") |
| 54 | |
| 55 | yield |
| 56 | await container.db_config().close() |
| 57 | await container.ws_service().worker_stop() |
| 58 | await container.rmq_producer().close() |
| 59 | await container.rmq_consumer().close() |
| 60 | await container.ws_manager().close_all() |
| 61 | container.unwire() |
| 62 | |
| 63 | |
| 64 | app = FastAPI( |
nothing calls this directly
no test coverage detected