Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform): Fix service health check mechanism on app service (#10401)

Zamil Majdybf73b4289009
diff --git a/autogpt_platform/backend/backend/monitoring/notification_monitor.py b/autogpt_platform/backend/backend/monitoring/notification_monitor.py
index 418ef23e0e..3326dd91a2 100644
--- a/autogpt_platform/backend/backend/monitoring/notification_monitor.py
+++ b/autogpt_platform/backend/backend/monitoring/notification_monitor.py
@@ -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}")
diff --git a/autogpt_platform/backend/backend/server/rest_api.py b/autogpt_platform/backend/backend/server/rest_api.py
index b81e53d7b8..abdb7448c5 100644
--- a/autogpt_platform/backend/backend/server/rest_api.py
+++ b/autogpt_platform/backend/backend/server/rest_api.py
@@ -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"}
diff --git a/autogpt_platform/backend/backend/util/service.py b/autogpt_platform/backend/backend/util/service.py
index d9e3e55eb8..1096101107 100644
--- a/autogpt_platform/backend/backend/util/service.py
+++ b/autogpt_platform/backend/backend/util/service.py
@@ -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