Add more services
This commit is contained in:
@@ -9,6 +9,11 @@ from .training_client import TrainingServiceClient
|
||||
from .sales_client import SalesServiceClient
|
||||
from .external_client import ExternalServiceClient
|
||||
from .forecast_client import ForecastServiceClient
|
||||
from .inventory_client import InventoryServiceClient
|
||||
from .orders_client import OrdersServiceClient
|
||||
from .production_client import ProductionServiceClient
|
||||
from .recipes_client import RecipesServiceClient
|
||||
from .suppliers_client import SuppliersServiceClient
|
||||
|
||||
# Import config
|
||||
from shared.config.base import BaseServiceSettings
|
||||
@@ -56,6 +61,56 @@ def get_forecast_client(config: BaseServiceSettings = None, service_name: str =
|
||||
_client_cache[cache_key] = ForecastServiceClient(config, service_name)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
def get_inventory_client(config: BaseServiceSettings = None, service_name: str = "unknown") -> InventoryServiceClient:
|
||||
"""Get or create an inventory service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
cache_key = f"inventory_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = InventoryServiceClient(config)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
def get_orders_client(config: BaseServiceSettings = None, service_name: str = "unknown") -> OrdersServiceClient:
|
||||
"""Get or create an orders service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
cache_key = f"orders_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = OrdersServiceClient(config)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
def get_production_client(config: BaseServiceSettings = None, service_name: str = "unknown") -> ProductionServiceClient:
|
||||
"""Get or create a production service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
cache_key = f"production_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = ProductionServiceClient(config)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
def get_recipes_client(config: BaseServiceSettings = None, service_name: str = "unknown") -> RecipesServiceClient:
|
||||
"""Get or create a recipes service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
cache_key = f"recipes_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = RecipesServiceClient(config)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
def get_suppliers_client(config: BaseServiceSettings = None, service_name: str = "unknown") -> SuppliersServiceClient:
|
||||
"""Get or create a suppliers service client"""
|
||||
if config is None:
|
||||
from app.core.config import settings as config
|
||||
|
||||
cache_key = f"suppliers_{service_name}"
|
||||
if cache_key not in _client_cache:
|
||||
_client_cache[cache_key] = SuppliersServiceClient(config)
|
||||
return _client_cache[cache_key]
|
||||
|
||||
|
||||
class ServiceClients:
|
||||
"""Convenient wrapper for all service clients"""
|
||||
@@ -69,6 +124,11 @@ class ServiceClients:
|
||||
self._sales_client = None
|
||||
self._external_client = None
|
||||
self._forecast_client = None
|
||||
self._inventory_client = None
|
||||
self._orders_client = None
|
||||
self._production_client = None
|
||||
self._recipes_client = None
|
||||
self._suppliers_client = None
|
||||
|
||||
def _get_default_config(self):
|
||||
"""Get default config from app settings"""
|
||||
@@ -105,6 +165,41 @@ class ServiceClients:
|
||||
if self._forecast_client is None:
|
||||
self._forecast_client = get_forecast_client(self.config, self.service_name)
|
||||
return self._forecast_client
|
||||
|
||||
@property
|
||||
def inventory(self) -> InventoryServiceClient:
|
||||
"""Get inventory service client"""
|
||||
if self._inventory_client is None:
|
||||
self._inventory_client = get_inventory_client(self.config, self.service_name)
|
||||
return self._inventory_client
|
||||
|
||||
@property
|
||||
def orders(self) -> OrdersServiceClient:
|
||||
"""Get orders service client"""
|
||||
if self._orders_client is None:
|
||||
self._orders_client = get_orders_client(self.config, self.service_name)
|
||||
return self._orders_client
|
||||
|
||||
@property
|
||||
def production(self) -> ProductionServiceClient:
|
||||
"""Get production service client"""
|
||||
if self._production_client is None:
|
||||
self._production_client = get_production_client(self.config, self.service_name)
|
||||
return self._production_client
|
||||
|
||||
@property
|
||||
def recipes(self) -> RecipesServiceClient:
|
||||
"""Get recipes service client"""
|
||||
if self._recipes_client is None:
|
||||
self._recipes_client = get_recipes_client(self.config, self.service_name)
|
||||
return self._recipes_client
|
||||
|
||||
@property
|
||||
def suppliers(self) -> SuppliersServiceClient:
|
||||
"""Get suppliers service client"""
|
||||
if self._suppliers_client is None:
|
||||
self._suppliers_client = get_suppliers_client(self.config, self.service_name)
|
||||
return self._suppliers_client
|
||||
|
||||
# Convenience function to get all clients
|
||||
def get_service_clients(config: BaseServiceSettings = None, service_name: str = "unknown") -> ServiceClients:
|
||||
@@ -119,10 +214,20 @@ __all__ = [
|
||||
'SalesServiceClient',
|
||||
'ExternalServiceClient',
|
||||
'ForecastServiceClient',
|
||||
'InventoryServiceClient',
|
||||
'OrdersServiceClient',
|
||||
'ProductionServiceClient',
|
||||
'RecipesServiceClient',
|
||||
'SuppliersServiceClient',
|
||||
'ServiceClients',
|
||||
'get_training_client',
|
||||
'get_sales_client',
|
||||
'get_external_client',
|
||||
'get_forecast_client',
|
||||
'get_inventory_client',
|
||||
'get_orders_client',
|
||||
'get_production_client',
|
||||
'get_recipes_client',
|
||||
'get_suppliers_client',
|
||||
'get_service_clients'
|
||||
]
|
||||
Reference in New Issue
Block a user