feat(backend): Avoid connecting the same host and falling-back to defined api_host (#9668)

### Changes 🏗️

Avoid connecting the same host and falling-back to defined api_host.

### Checklist 📋

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [ ] I have tested my changes according to the test plan:
- [ ] Define a custom DBMANAGER_HOST, RestService should access the
`db_manager` service using localhost.
This commit is contained in:
Zamil Majdy
2025-03-21 18:41:01 +07:00
committed by GitHub
parent 42232f55e8
commit a1ac7b18f9

View File

@@ -44,7 +44,7 @@ from Pyro5 import config as pyro_config
from backend.data import db, rabbitmq, redis
from backend.util.exceptions import InsufficientBalanceError
from backend.util.json import to_dict
from backend.util.process import AppProcess
from backend.util.process import AppProcess, get_service_name
from backend.util.retry import conn_retry
from backend.util.settings import Config, Secrets
@@ -190,7 +190,17 @@ class BaseAppService(AppProcess, ABC):
@classmethod
def get_host(cls) -> str:
return os.environ.get(f"{cls.service_name.upper()}_HOST", api_host)
source_host = os.environ.get(f"{get_service_name().upper()}_HOST", api_host)
target_host = os.environ.get(f"{cls.service_name.upper()}_HOST", api_host)
if source_host == target_host and source_host != api_host:
logger.warning(
f"Service {cls.service_name} is the same host as the source service."
f"Use the localhost of {api_host} instead."
)
return api_host
return target_host
@property
def rabbit(self) -> rabbitmq.AsyncRabbitMQ: