sending email async with celery
This commit is contained in:
29
app.py
29
app.py
@@ -1,5 +1,5 @@
|
||||
import random
|
||||
from flask import Flask, send_from_directory
|
||||
from flask import Flask, send_from_directory, jsonify
|
||||
from flask_migrate import Migrate
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
@@ -14,6 +14,7 @@ import click
|
||||
from utils import timeago
|
||||
from extensions import db, login_manager, csrf
|
||||
from utils.email_templates import create_default_templates
|
||||
from celery_worker import init_celery, celery
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
@@ -35,6 +36,9 @@ def create_app():
|
||||
login_manager.login_view = 'auth.login'
|
||||
csrf.init_app(app)
|
||||
|
||||
# Initialize Celery
|
||||
init_celery(app)
|
||||
|
||||
@app.context_processor
|
||||
def inject_csrf_token():
|
||||
return dict(csrf_token=generate_csrf())
|
||||
@@ -48,13 +52,32 @@ def create_app():
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
|
||||
# Health check endpoint
|
||||
@app.route('/health')
|
||||
def health_check():
|
||||
try:
|
||||
# Check database connection
|
||||
db.session.execute('SELECT 1')
|
||||
# Check Redis connection
|
||||
celery.control.inspect().ping()
|
||||
return jsonify({
|
||||
'status': 'healthy',
|
||||
'database': 'connected',
|
||||
'redis': 'connected'
|
||||
}), 200
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
'status': 'unhealthy',
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
# Initialize routes
|
||||
from routes import init_app
|
||||
init_app(app)
|
||||
app.register_blueprint(room_files_bp, url_prefix='/api/rooms')
|
||||
app.register_blueprint(user_bp, url_prefix='/api/users')
|
||||
app.register_blueprint(room_members_bp, url_prefix='/api/rooms')
|
||||
app.register_blueprint(trash_bp, url_prefix='/api/rooms')
|
||||
app.register_blueprint(user_bp)
|
||||
app.register_blueprint(trash_bp, url_prefix='/api/trash')
|
||||
|
||||
@app.cli.command("cleanup-trash")
|
||||
def cleanup_trash_command():
|
||||
|
||||
Reference in New Issue
Block a user