Enhance bot functionality and refactor database interactions
- Added `ca-certificates` installation to Dockerfile for improved network security. - Updated health check command in Dockerfile to include better timeout handling. - Refactored `run_helper.py` to implement proper signal handling and logging during shutdown. - Transitioned database operations to an asynchronous model in `async_db.py`, improving performance and responsiveness. - Updated database schema to support new foreign key relationships and optimized indexing for better query performance. - Enhanced various bot handlers to utilize async database methods, improving overall efficiency and user experience. - Removed obsolete database and fix scripts to streamline the project structure.
This commit is contained in:
@@ -59,10 +59,43 @@ class MetricsServer:
|
||||
|
||||
async def health_handler(self, request: web.Request) -> web.Response:
|
||||
"""Handle /health endpoint for health checks."""
|
||||
return web.Response(
|
||||
text="OK",
|
||||
content_type='text/plain'
|
||||
)
|
||||
try:
|
||||
# Проверяем доступность метрик
|
||||
if not metrics:
|
||||
return web.Response(
|
||||
text="ERROR: Metrics not available",
|
||||
content_type='text/plain',
|
||||
status=503
|
||||
)
|
||||
|
||||
# Проверяем, что можем получить метрики
|
||||
try:
|
||||
metrics_data = metrics.get_metrics()
|
||||
if not metrics_data:
|
||||
return web.Response(
|
||||
text="ERROR: Empty metrics",
|
||||
content_type='text/plain',
|
||||
status=503
|
||||
)
|
||||
except Exception as e:
|
||||
return web.Response(
|
||||
text=f"ERROR: Metrics generation failed: {e}",
|
||||
content_type='text/plain',
|
||||
status=503
|
||||
)
|
||||
|
||||
return web.Response(
|
||||
text="OK",
|
||||
content_type='text/plain',
|
||||
status=200
|
||||
)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Health check failed: {e}")
|
||||
return web.Response(
|
||||
text=f"ERROR: Health check failed: {e}",
|
||||
content_type='text/plain',
|
||||
status=500
|
||||
)
|
||||
|
||||
async def start(self) -> None:
|
||||
"""Start the HTTP server."""
|
||||
@@ -122,5 +155,12 @@ async def stop_metrics_server() -> None:
|
||||
"""Stop metrics server if running."""
|
||||
global metrics_server
|
||||
if metrics_server:
|
||||
await metrics_server.stop()
|
||||
metrics_server = None
|
||||
try:
|
||||
await metrics_server.stop()
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("Metrics server stopped successfully")
|
||||
except Exception as e:
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.error(f"Error stopping metrics server: {e}")
|
||||
finally:
|
||||
metrics_server = None
|
||||
|
||||
Reference in New Issue
Block a user