backup
This commit is contained in:
@@ -1,53 +1,56 @@
|
||||
"""
|
||||
Health Check Endpoints
|
||||
|
||||
This module provides comprehensive health check endpoints for monitoring
|
||||
the AniWorld application's status, dependencies, and performance metrics.
|
||||
This module provides basic health check endpoints for monitoring
|
||||
the AniWorld application's status.
|
||||
"""
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
from flask import Blueprint, jsonify
|
||||
import time
|
||||
import os
|
||||
import sqlite3
|
||||
import psutil
|
||||
from datetime import datetime
|
||||
import threading
|
||||
from health_monitor import health_monitor
|
||||
from database_manager import database_manager
|
||||
from performance_optimizer import memory_monitor
|
||||
from config import config
|
||||
|
||||
|
||||
# Blueprint for health check endpoints
|
||||
health_bp = Blueprint('health_check', __name__)
|
||||
|
||||
# Health check cache to avoid expensive operations on every request
|
||||
_health_cache = {}
|
||||
_cache_lock = threading.Lock()
|
||||
_cache_ttl = 30 # Cache for 30 seconds
|
||||
health_bp = Blueprint('health_check', __name__, url_prefix='/api/health')
|
||||
|
||||
|
||||
def get_cached_health_data(cache_key, check_function, ttl=None):
|
||||
"""Get health data from cache or execute check function."""
|
||||
current_time = time.time()
|
||||
ttl = ttl or _cache_ttl
|
||||
|
||||
with _cache_lock:
|
||||
if cache_key in _health_cache:
|
||||
cached_data, timestamp = _health_cache[cache_key]
|
||||
if current_time - timestamp < ttl:
|
||||
return cached_data
|
||||
@health_bp.route('/status')
|
||||
def get_basic_health():
|
||||
"""Get basic application health status."""
|
||||
try:
|
||||
# Basic system metrics
|
||||
memory = psutil.virtual_memory()
|
||||
disk = psutil.disk_usage('/')
|
||||
|
||||
# Execute check and cache result
|
||||
try:
|
||||
result = check_function()
|
||||
_health_cache[cache_key] = (result, current_time)
|
||||
return result
|
||||
except Exception as e:
|
||||
return {'status': 'error', 'message': str(e)}
|
||||
return jsonify({
|
||||
'status': 'healthy',
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'system': {
|
||||
'memory_usage_percent': memory.percent,
|
||||
'disk_usage_percent': disk.percent,
|
||||
'uptime': time.time()
|
||||
},
|
||||
'application': {
|
||||
'status': 'running',
|
||||
'version': '1.0.0'
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
'status': 'error',
|
||||
'message': str(e),
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}), 500
|
||||
|
||||
|
||||
@health_bp.route('/health')
|
||||
@health_bp.route('/ping')
|
||||
def ping():
|
||||
"""Simple ping endpoint."""
|
||||
return jsonify({
|
||||
'status': 'ok',
|
||||
'timestamp': datetime.now().isoformat()
|
||||
})
|
||||
@health_bp.route('/api/health')
|
||||
def basic_health():
|
||||
"""Basic health check endpoint for load balancers."""
|
||||
|
||||
@@ -3,7 +3,7 @@ API endpoints for logging configuration and management.
|
||||
"""
|
||||
|
||||
from flask import Blueprint, jsonify, request, send_file
|
||||
from auth import require_auth
|
||||
from web.controllers.auth_controller import require_auth
|
||||
from config import config
|
||||
import logging
|
||||
import os
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from auth import require_auth
|
||||
from process_locks import (
|
||||
from web.controllers.auth_controller import require_auth
|
||||
from shared.utils.process_utils import (
|
||||
process_lock_manager,
|
||||
RESCAN_LOCK,
|
||||
DOWNLOAD_LOCK,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from auth import require_auth
|
||||
from scheduler import get_scheduler
|
||||
from web.controllers.auth_controller import require_auth
|
||||
from application.services.scheduler_service import get_scheduler
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -240,7 +240,7 @@ def require_auth(f):
|
||||
'code': 'AUTH_REQUIRED'
|
||||
}), 401
|
||||
else:
|
||||
return redirect(url_for('login'))
|
||||
return redirect(url_for('auth.login'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
@@ -268,6 +268,6 @@ def optional_auth(f):
|
||||
'code': 'AUTH_REQUIRED'
|
||||
}), 401
|
||||
else:
|
||||
return redirect(url_for('login'))
|
||||
return redirect(url_for('auth.login'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
Reference in New Issue
Block a user