File tree Expand file tree Collapse file tree 1 file changed +17
-18
lines changed
Expand file tree Collapse file tree 1 file changed +17
-18
lines changed Original file line number Diff line number Diff line change 11import time
22import uuid
3- from contextlib import asynccontextmanager
43
54import structlog
65from fastapi import FastAPI , Request
2625 },
2726]
2827
29-
30- @asynccontextmanager
31- async def lifespan (app : FastAPI ):
32- """Lifespan context manager for startup and shutdown events."""
33- # Startup
34- logger .info (
35- "Application startup complete" ,
36- service = "backend-py" ,
37- version = "0.1.0" ,
38- api_prefix = api_prefix_v1 ,
39- )
40- yield
41- # Shutdown
42- logger .info ("Application shutdown initiated" )
43-
44-
4528app = FastAPI (
4629 title = OpenAPIInfo ["title" ],
4730 version = OpenAPIInfo ["version" ],
4831 openapi_tags = tags_metadata ,
49- lifespan = lifespan ,
5032)
5133
5234
@@ -165,3 +147,20 @@ async def root():
165147
166148
167149app .include_router (user_router , prefix = api_prefix_v1 + "/user" , tags = ["User CRUD" ])
150+
151+
152+ # Startup event
153+ @app .on_event ("startup" )
154+ async def startup_event ():
155+ logger .info (
156+ "Application startup complete" ,
157+ service = "backend-py" ,
158+ version = "0.1.0" ,
159+ api_prefix = api_prefix_v1 ,
160+ )
161+
162+
163+ # Shutdown event
164+ @app .on_event ("shutdown" )
165+ async def shutdown_event ():
166+ logger .info ("Application shutdown initiated" )
You can’t perform that action at this time.
0 commit comments