mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(platform): Fix service health check mechanism on app service (#10401)
## Summary - Introduced correct health check API for AppService - Fixed service health check mechanism to properly handle health status monitoring ## Changes Made - Updated health check implementation in AppService. - Make rest service health check checks the health of DatabaseManager too. ## Test plan - [x] Verify health check endpoint responds correctly - [x] Test health check mechanism under various service states - [x] Validate monitoring and alerting integration 🤖 Generated with [Claude Code](https://claude.ai/code)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from autogpt_libs.utils.cache import thread_cached
|
||||
from prisma.enums import NotificationType
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -16,6 +17,11 @@ class NotificationJobArgs(BaseModel):
|
||||
cron: str
|
||||
|
||||
|
||||
@thread_cached
|
||||
def get_notification_manager_client():
|
||||
return get_service_client(NotificationManagerClient)
|
||||
|
||||
|
||||
def process_existing_batches(**kwargs):
|
||||
"""Process existing notification batches."""
|
||||
args = NotificationJobArgs(**kwargs)
|
||||
@@ -23,7 +29,7 @@ def process_existing_batches(**kwargs):
|
||||
logging.info(
|
||||
f"Processing existing batches for notification type {args.notification_types}"
|
||||
)
|
||||
get_service_client(NotificationManagerClient).process_existing_batches(
|
||||
get_notification_manager_client().process_existing_batches(
|
||||
args.notification_types
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -34,6 +40,6 @@ def process_weekly_summary(**kwargs):
|
||||
"""Process weekly summary notifications."""
|
||||
try:
|
||||
logging.info("Processing weekly summary")
|
||||
get_service_client(NotificationManagerClient).queue_weekly_summary()
|
||||
get_notification_manager_client().queue_weekly_summary()
|
||||
except Exception as e:
|
||||
logger.exception(f"Error processing weekly summary: {e}")
|
||||
|
||||
@@ -14,6 +14,7 @@ from autogpt_libs.feature_flag.client import (
|
||||
shutdown_launchdarkly,
|
||||
)
|
||||
from autogpt_libs.logging.utils import generate_uvicorn_config
|
||||
from autogpt_libs.utils.cache import thread_cached
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.routing import APIRoute
|
||||
|
||||
@@ -212,8 +213,19 @@ app.include_router(
|
||||
app.mount("/external-api", external_app)
|
||||
|
||||
|
||||
@thread_cached
|
||||
def get_db_async_client():
|
||||
from backend.executor import DatabaseManagerAsyncClient
|
||||
|
||||
return backend.util.service.get_service_client(
|
||||
DatabaseManagerAsyncClient,
|
||||
health_check=False,
|
||||
)
|
||||
|
||||
|
||||
@app.get(path="/health", tags=["health"], dependencies=[])
|
||||
async def health():
|
||||
await get_db_async_client().health_check_async()
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
|
||||
@@ -216,7 +216,10 @@ class AppService(BaseAppService, ABC):
|
||||
methods=["POST"],
|
||||
)
|
||||
self.fastapi_app.add_api_route(
|
||||
"/health_check", self.health_check, methods=["POST"]
|
||||
"/health_check", self.health_check, methods=["POST", "GET"]
|
||||
)
|
||||
self.fastapi_app.add_api_route(
|
||||
"/health_check_async", self.health_check, methods=["POST", "GET"]
|
||||
)
|
||||
self.fastapi_app.add_exception_handler(
|
||||
ValueError, self._handle_internal_http_error(400)
|
||||
@@ -248,6 +251,9 @@ class AppServiceClient(ABC):
|
||||
def health_check(self):
|
||||
pass
|
||||
|
||||
async def health_check_async(self):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user