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