feat(scheduler): implement scheduler service for background tasks and credit refills; add endpoints for admin control

This commit is contained in:
JSC
2025-07-02 13:39:17 +02:00
parent 703212656f
commit 1b597f4047
6 changed files with 304 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ from flask_jwt_extended import JWTManager
from app.database import init_db
from app.services.auth_service import AuthService
from app.services.scheduler_service import scheduler_service
# Global auth service instance
auth_service = AuthService()
@@ -60,10 +61,20 @@ def create_app():
# Initialize authentication service with app
auth_service.init_app(app)
# Start scheduler for background tasks
scheduler_service.start()
# Register blueprints
from app.routes import auth, main
app.register_blueprint(main.bp, url_prefix="/api")
app.register_blueprint(auth.bp, url_prefix="/api/auth")
# Shutdown scheduler when app is torn down
@app.teardown_appcontext
def shutdown_scheduler(exception):
"""Stop scheduler when app context is torn down."""
if exception:
scheduler_service.stop()
return app