New alert service
This commit is contained in:
@@ -16,7 +16,7 @@ from shared.service_base import StandardFastAPIService
|
||||
class OrchestratorService(StandardFastAPIService):
|
||||
"""Orchestrator Service with standardized setup"""
|
||||
|
||||
expected_migration_version = "00001"
|
||||
expected_migration_version = "001_initial_schema"
|
||||
|
||||
async def verify_migrations(self):
|
||||
"""Verify database schema matches the latest migrations"""
|
||||
@@ -38,6 +38,9 @@ class OrchestratorService(StandardFastAPIService):
|
||||
'orchestration_runs'
|
||||
]
|
||||
|
||||
self.rabbitmq_client = None
|
||||
self.event_publisher = None
|
||||
|
||||
super().__init__(
|
||||
service_name="orchestrator-service",
|
||||
app_name=settings.APP_NAME,
|
||||
@@ -45,20 +48,51 @@ class OrchestratorService(StandardFastAPIService):
|
||||
version=settings.VERSION,
|
||||
api_prefix="", # Empty because RouteBuilder already includes /api/v1
|
||||
database_manager=database_manager,
|
||||
expected_tables=orchestrator_expected_tables
|
||||
expected_tables=orchestrator_expected_tables,
|
||||
enable_messaging=True # Enable RabbitMQ for event publishing
|
||||
)
|
||||
|
||||
async def _setup_messaging(self):
|
||||
"""Setup messaging for orchestrator service"""
|
||||
from shared.messaging import UnifiedEventPublisher, RabbitMQClient
|
||||
try:
|
||||
self.rabbitmq_client = RabbitMQClient(settings.RABBITMQ_URL, service_name="orchestrator-service")
|
||||
await self.rabbitmq_client.connect()
|
||||
# Create event publisher
|
||||
self.event_publisher = UnifiedEventPublisher(self.rabbitmq_client, "orchestrator-service")
|
||||
self.logger.info("Orchestrator service messaging setup completed")
|
||||
except Exception as e:
|
||||
self.logger.error("Failed to setup orchestrator messaging", error=str(e))
|
||||
raise
|
||||
|
||||
async def _cleanup_messaging(self):
|
||||
"""Cleanup messaging for orchestrator service"""
|
||||
try:
|
||||
if self.rabbitmq_client:
|
||||
await self.rabbitmq_client.disconnect()
|
||||
self.logger.info("Orchestrator service messaging cleanup completed")
|
||||
except Exception as e:
|
||||
self.logger.error("Error during orchestrator messaging cleanup", error=str(e))
|
||||
|
||||
async def on_startup(self, app: FastAPI):
|
||||
"""Custom startup logic for orchestrator service"""
|
||||
# Verify migrations first
|
||||
await self.verify_migrations()
|
||||
|
||||
# Call parent startup (includes database, messaging, etc.)
|
||||
await super().on_startup(app)
|
||||
|
||||
self.logger.info("Orchestrator Service starting up...")
|
||||
|
||||
# Initialize orchestrator scheduler service
|
||||
# Initialize orchestrator scheduler service with EventPublisher
|
||||
from app.services.orchestrator_service import OrchestratorSchedulerService
|
||||
scheduler_service = OrchestratorSchedulerService(settings)
|
||||
scheduler_service = OrchestratorSchedulerService(self.event_publisher, settings)
|
||||
await scheduler_service.start()
|
||||
app.state.scheduler_service = scheduler_service
|
||||
self.logger.info("Orchestrator scheduler service started")
|
||||
|
||||
# REMOVED: Delivery tracking service - moved to procurement service (domain ownership)
|
||||
|
||||
async def on_shutdown(self, app: FastAPI):
|
||||
"""Custom shutdown logic for orchestrator service"""
|
||||
self.logger.info("Orchestrator Service shutting down...")
|
||||
@@ -68,6 +102,7 @@ class OrchestratorService(StandardFastAPIService):
|
||||
await app.state.scheduler_service.stop()
|
||||
self.logger.info("Orchestrator scheduler service stopped")
|
||||
|
||||
|
||||
def get_service_features(self):
|
||||
"""Return orchestrator-specific features"""
|
||||
return [
|
||||
@@ -94,45 +129,10 @@ service.setup_standard_endpoints()
|
||||
# Include routers
|
||||
# BUSINESS: Orchestration operations
|
||||
from app.api.orchestration import router as orchestration_router
|
||||
from app.api.dashboard import router as dashboard_router
|
||||
from app.api.enterprise_dashboard import router as enterprise_dashboard_router
|
||||
from app.api.internal import router as internal_router
|
||||
service.add_router(orchestration_router)
|
||||
service.add_router(dashboard_router)
|
||||
service.add_router(enterprise_dashboard_router)
|
||||
service.add_router(internal_router)
|
||||
|
||||
# Add enterprise dashboard service to dependencies
|
||||
from app.services.enterprise_dashboard_service import EnterpriseDashboardService
|
||||
from shared.clients import (
|
||||
get_tenant_client,
|
||||
get_forecast_client,
|
||||
get_production_client,
|
||||
get_sales_client,
|
||||
get_inventory_client,
|
||||
get_procurement_client,
|
||||
get_distribution_client
|
||||
)
|
||||
|
||||
def get_enterprise_dashboard_service() -> EnterpriseDashboardService:
|
||||
tenant_client = get_tenant_client(settings)
|
||||
forecast_client = get_forecast_client(settings)
|
||||
production_client = get_production_client(settings)
|
||||
sales_client = get_sales_client(settings)
|
||||
inventory_client = get_inventory_client(settings)
|
||||
distribution_client = get_distribution_client(settings)
|
||||
procurement_client = get_procurement_client(settings)
|
||||
|
||||
return EnterpriseDashboardService(
|
||||
tenant_client=tenant_client,
|
||||
forecast_client=forecast_client,
|
||||
production_client=production_client,
|
||||
sales_client=sales_client,
|
||||
inventory_client=inventory_client,
|
||||
distribution_client=distribution_client,
|
||||
procurement_client=procurement_client
|
||||
)
|
||||
|
||||
# INTERNAL: Service-to-service endpoints
|
||||
from app.api import internal_demo
|
||||
service.add_router(internal_demo.router)
|
||||
|
||||
Reference in New Issue
Block a user