Fix TTS server status errors and startup warnings
- Fixed 'app is not defined' errors by using current_app - Improved TTS health check to handle missing /health endpoint - Fixed database trigger creation to be idempotent - Added .env.example with all configuration options - Updated README with security configuration instructions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, request, jsonify, render_template, redirect, url_for, session
|
||||
from flask import Blueprint, request, jsonify, render_template, redirect, url_for, session, current_app
|
||||
from functools import wraps
|
||||
import os
|
||||
import logging
|
||||
@@ -483,14 +483,26 @@ def check_system_health():
|
||||
health['overall'] = 'degraded'
|
||||
|
||||
# Check TTS Server
|
||||
tts_server_url = app.config.get('TTS_SERVER_URL')
|
||||
tts_server_url = current_app.config.get('TTS_SERVER_URL')
|
||||
if tts_server_url:
|
||||
try:
|
||||
import requests
|
||||
response = requests.get(f"{tts_server_url}/health", timeout=2)
|
||||
# Extract base URL from the speech endpoint
|
||||
base_url = tts_server_url.rsplit('/v1/audio/speech', 1)[0] if '/v1/audio/speech' in tts_server_url else tts_server_url
|
||||
health_url = f"{base_url}/health" if not tts_server_url.endswith('/health') else tts_server_url
|
||||
response = requests.get(health_url, timeout=2)
|
||||
if response.status_code == 200:
|
||||
health['tts'] = 'healthy'
|
||||
health['tts_details'] = response.json() if response.headers.get('content-type') == 'application/json' else {}
|
||||
elif response.status_code == 404:
|
||||
# Try voices endpoint as fallback
|
||||
voices_url = f"{base_url}/voices" if base_url else f"{tts_server_url.rsplit('/speech', 1)[0]}/voices"
|
||||
voices_response = requests.get(voices_url, timeout=2)
|
||||
if voices_response.status_code == 200:
|
||||
health['tts'] = 'healthy'
|
||||
else:
|
||||
health['tts'] = 'unhealthy'
|
||||
health['overall'] = 'degraded'
|
||||
else:
|
||||
health['tts'] = 'unhealthy'
|
||||
health['overall'] = 'degraded'
|
||||
@@ -522,8 +534,8 @@ def get_tts_status():
|
||||
}
|
||||
|
||||
# Check configuration
|
||||
tts_server_url = app.config.get('TTS_SERVER_URL')
|
||||
tts_api_key = app.config.get('TTS_API_KEY')
|
||||
tts_server_url = current_app.config.get('TTS_SERVER_URL')
|
||||
tts_api_key = current_app.config.get('TTS_API_KEY')
|
||||
|
||||
if tts_server_url:
|
||||
tts_info['configured'] = True
|
||||
@@ -538,7 +550,11 @@ def get_tts_status():
|
||||
headers['Authorization'] = f'Bearer {tts_api_key}'
|
||||
|
||||
# Check health endpoint
|
||||
response = requests.get(f"{tts_server_url}/health", headers=headers, timeout=3)
|
||||
# Extract base URL from the speech endpoint
|
||||
base_url = tts_server_url.rsplit('/v1/audio/speech', 1)[0] if '/v1/audio/speech' in tts_server_url else tts_server_url
|
||||
health_url = f"{base_url}/health" if not tts_server_url.endswith('/health') else tts_server_url
|
||||
|
||||
response = requests.get(health_url, headers=headers, timeout=3)
|
||||
if response.status_code == 200:
|
||||
tts_info['status'] = 'healthy'
|
||||
if response.headers.get('content-type') == 'application/json':
|
||||
@@ -549,11 +565,16 @@ def get_tts_status():
|
||||
|
||||
# Try to get voice list
|
||||
try:
|
||||
voices_response = requests.get(f"{tts_server_url}/voices", headers=headers, timeout=3)
|
||||
voices_url = f"{base_url}/voices" if base_url else f"{tts_server_url.rsplit('/speech', 1)[0]}/voices"
|
||||
voices_response = requests.get(voices_url, headers=headers, timeout=3)
|
||||
if voices_response.status_code == 200 and voices_response.headers.get('content-type') == 'application/json':
|
||||
voices_data = voices_response.json()
|
||||
tts_info['details']['available_voices'] = voices_data.get('voices', [])
|
||||
tts_info['details']['voice_count'] = len(voices_data.get('voices', []))
|
||||
# If we can get voices, consider the server healthy even if health endpoint doesn't exist
|
||||
if tts_info['status'] == 'unhealthy' and response.status_code == 404:
|
||||
tts_info['status'] = 'healthy'
|
||||
tts_info['details'].pop('error', None)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -636,7 +657,7 @@ def stream_updates():
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
return app.response_class(
|
||||
return current_app.response_class(
|
||||
generate(),
|
||||
mimetype='text/event-stream',
|
||||
headers={
|
||||
|
Reference in New Issue
Block a user