Spaces:
Running
Running
Update app/main.py
Browse files- app/main.py +18 -3
app/main.py
CHANGED
|
@@ -3,6 +3,10 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
| 3 |
from .routes import file_routes
|
| 4 |
from . import create_app
|
| 5 |
from .services.storage_service import StorageService
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = create_app()
|
| 8 |
storage_service = StorageService()
|
|
@@ -12,8 +16,13 @@ app.include_router(file_routes.router, prefix="/api")
|
|
| 12 |
|
| 13 |
# Set up scheduler for cleanup
|
| 14 |
scheduler = AsyncIOScheduler()
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
@app.get("/")
|
| 19 |
async def root():
|
|
@@ -22,4 +31,10 @@ async def root():
|
|
| 22 |
# Handle shutdown
|
| 23 |
@app.on_event("shutdown")
|
| 24 |
async def shutdown_event():
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from .routes import file_routes
|
| 4 |
from . import create_app
|
| 5 |
from .services.storage_service import StorageService
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
app = create_app()
|
| 12 |
storage_service = StorageService()
|
|
|
|
| 16 |
|
| 17 |
# Set up scheduler for cleanup
|
| 18 |
scheduler = AsyncIOScheduler()
|
| 19 |
+
|
| 20 |
+
@app.on_event("startup")
|
| 21 |
+
async def startup_event():
|
| 22 |
+
logger.info("Starting up the application")
|
| 23 |
+
scheduler.add_job(storage_service.cleanup_expired_files, 'interval', minutes=1, id='cleanup_job')
|
| 24 |
+
scheduler.start()
|
| 25 |
+
logger.info("Scheduler started")
|
| 26 |
|
| 27 |
@app.get("/")
|
| 28 |
async def root():
|
|
|
|
| 31 |
# Handle shutdown
|
| 32 |
@app.on_event("shutdown")
|
| 33 |
async def shutdown_event():
|
| 34 |
+
logger.info("Shutting down the application")
|
| 35 |
+
scheduler.shutdown()
|
| 36 |
+
logger.info("Scheduler shut down")
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
import uvicorn
|
| 40 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|