feat(platform): Move DatabaseManager away from RestAPI as a standalone sevice (#10437)

It's hard to debug two processes running in the same pod. We need to
decouple the two processes into two services.

### Changes 🏗️

Move DatabaseManager away from RestAPI as a standalone serice

### Checklist 📋

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
  <!-- Put your test plan here: -->
  - [x] Manual test
This commit is contained in:
Zamil Majdy
2025-07-23 21:37:26 +08:00
committed by GitHub
parent 708e84fba6
commit 51a39ef81a
5 changed files with 16 additions and 22 deletions

View File

@@ -1,6 +1,10 @@
import logging
from typing import TYPE_CHECKING
from dotenv import load_dotenv
load_dotenv()
if TYPE_CHECKING:
from backend.util.process import AppProcess
@@ -38,7 +42,7 @@ def main(**kwargs):
from backend.server.ws_api import WebsocketServer
run_processes(
DatabaseManager(),
DatabaseManager().set_log_level("warning"),
ExecutionManager(),
Scheduler(),
NotificationManager(),

View File

@@ -391,9 +391,6 @@ async def create_or_add_to_user_notification_batch(
notification_data: NotificationEventModel,
) -> UserNotificationBatchDTO:
try:
logger.info(
f"Creating or adding to notification batch for {user_id} with type {notification_type} and data {notification_data}"
)
if not notification_data.data:
raise ValueError("Notification data must be provided")

View File

@@ -1,5 +1,4 @@
from backend.app import run_processes
from backend.executor import DatabaseManager
from backend.server.rest_api import AgentServer
@@ -7,10 +6,7 @@ def main():
"""
Run all the processes required for the AutoGPT-server REST API.
"""
run_processes(
DatabaseManager(),
AgentServer(),
)
run_processes(AgentServer())
if __name__ == "__main__":

View File

@@ -14,7 +14,6 @@ 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
@@ -220,19 +219,8 @@ 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"}

View File

@@ -22,6 +22,7 @@ from typing import (
import httpx
import uvicorn
from autogpt_libs.logging.utils import generate_uvicorn_config
from fastapi import FastAPI, Request, responses
from pydantic import BaseModel, TypeAdapter, create_model
from tenacity import (
@@ -119,6 +120,12 @@ EXCEPTION_MAPPING = {
class AppService(BaseAppService, ABC):
fastapi_app: FastAPI
log_level: str = "info"
def set_log_level(self, log_level: str):
"""Set the uvicorn log level. Returns self for chaining."""
self.log_level = log_level
return self
@staticmethod
def _handle_internal_http_error(status_code: int = 500, log_error: bool = True):
@@ -191,12 +198,14 @@ class AppService(BaseAppService, ABC):
logger.info(
f"[{self.service_name}] Starting RPC server at http://{api_host}:{self.get_port()}"
)
server = uvicorn.Server(
uvicorn.Config(
self.fastapi_app,
host=api_host,
port=self.get_port(),
log_level="warning",
log_config=generate_uvicorn_config(),
log_level=self.log_level,
)
)
self.shared_event_loop.run_until_complete(server.serve())