tlong-ds commited on
Commit
22e081e
·
verified ·
1 Parent(s): 99c043f

Update services/api/db/auth.py

Browse files
Files changed (1) hide show
  1. services/api/db/auth.py +24 -2
services/api/db/auth.py CHANGED
@@ -25,12 +25,34 @@ import sys
25
  import importlib.util
26
  from services.api.db.token_utils import create_token, decode_token
27
  from sqlalchemy.orm import Session
 
28
 
29
  # Add parent directory to path to enable imports
30
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
31
 
32
- # Create single FastAPI instance
33
- app = FastAPI()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # Configure CORS with all needed origins
36
  app.add_middleware(
 
25
  import importlib.util
26
  from services.api.db.token_utils import create_token, decode_token
27
  from sqlalchemy.orm import Session
28
+ from contextlib import asynccontextmanager
29
 
30
  # Add parent directory to path to enable imports
31
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
32
 
33
+ # Define lifespan context manager for startup/shutdown events
34
+ @asynccontextmanager
35
+ async def lifespan(app: FastAPI):
36
+ # Startup
37
+ print("Starting up FastAPI application...")
38
+
39
+ # Start background tasks from upload endpoints
40
+ try:
41
+ # Import and start upload cleanup task
42
+ from services.api.upload_endpoints import start_cleanup_task
43
+ cleanup_task = start_cleanup_task()
44
+ print("Upload cleanup task started successfully")
45
+ except Exception as e:
46
+ print(f"Failed to start upload cleanup task: {e}")
47
+
48
+ yield
49
+
50
+ # Shutdown
51
+ print("Shutting down FastAPI application...")
52
+ # Any cleanup can be done here
53
+
54
+ # Create single FastAPI instance with lifespan
55
+ app = FastAPI(lifespan=lifespan)
56
 
57
  # Configure CORS with all needed origins
58
  app.add_middleware(