Improve the frontend 3
This commit is contained in:
0
services/orchestrator/app/core/__init__.py
Normal file
0
services/orchestrator/app/core/__init__.py
Normal file
103
services/orchestrator/app/core/config.py
Normal file
103
services/orchestrator/app/core/config.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# ================================================================
|
||||
# services/orchestrator/app/core/config.py
|
||||
# ================================================================
|
||||
"""
|
||||
Orchestrator Service Configuration
|
||||
"""
|
||||
|
||||
import os
|
||||
from pydantic import Field
|
||||
from shared.config.base import BaseServiceSettings
|
||||
|
||||
|
||||
class OrchestratorSettings(BaseServiceSettings):
|
||||
"""Orchestrator service specific settings"""
|
||||
|
||||
# Service Identity
|
||||
APP_NAME: str = "Orchestrator Service"
|
||||
SERVICE_NAME: str = "orchestrator-service"
|
||||
VERSION: str = "1.0.0"
|
||||
DESCRIPTION: str = "Automated orchestration of forecasting, production, and procurement workflows"
|
||||
|
||||
# Database configuration (minimal - only for audit logs)
|
||||
@property
|
||||
def DATABASE_URL(self) -> str:
|
||||
"""Build database URL from secure components"""
|
||||
# Try complete URL first (for backward compatibility)
|
||||
complete_url = os.getenv("ORCHESTRATOR_DATABASE_URL")
|
||||
if complete_url:
|
||||
return complete_url
|
||||
|
||||
# Build from components (secure approach)
|
||||
user = os.getenv("ORCHESTRATOR_DB_USER", "orchestrator_user")
|
||||
password = os.getenv("ORCHESTRATOR_DB_PASSWORD", "orchestrator_pass123")
|
||||
host = os.getenv("ORCHESTRATOR_DB_HOST", "localhost")
|
||||
port = os.getenv("ORCHESTRATOR_DB_PORT", "5432")
|
||||
name = os.getenv("ORCHESTRATOR_DB_NAME", "orchestrator_db")
|
||||
|
||||
return f"postgresql+asyncpg://{user}:{password}@{host}:{port}/{name}"
|
||||
|
||||
# Orchestration Settings
|
||||
ORCHESTRATION_ENABLED: bool = os.getenv("ORCHESTRATION_ENABLED", "true").lower() == "true"
|
||||
ORCHESTRATION_SCHEDULE: str = os.getenv("ORCHESTRATION_SCHEDULE", "0 5 * * *") # 5:30 AM daily (cron format)
|
||||
ORCHESTRATION_TIMEOUT_SECONDS: int = int(os.getenv("ORCHESTRATION_TIMEOUT_SECONDS", "600")) # 10 minutes
|
||||
|
||||
# Tenant Processing
|
||||
MAX_CONCURRENT_TENANTS: int = int(os.getenv("MAX_CONCURRENT_TENANTS", "5"))
|
||||
TENANT_TIMEOUT_SECONDS: int = int(os.getenv("TENANT_TIMEOUT_SECONDS", "180")) # 3 minutes per tenant
|
||||
|
||||
# Retry Configuration
|
||||
MAX_RETRIES: int = int(os.getenv("MAX_RETRIES", "3"))
|
||||
RETRY_DELAY_SECONDS: int = int(os.getenv("RETRY_DELAY_SECONDS", "30"))
|
||||
ENABLE_EXPONENTIAL_BACKOFF: bool = os.getenv("ENABLE_EXPONENTIAL_BACKOFF", "true").lower() == "true"
|
||||
|
||||
# Circuit Breaker
|
||||
CIRCUIT_BREAKER_ENABLED: bool = os.getenv("CIRCUIT_BREAKER_ENABLED", "true").lower() == "true"
|
||||
CIRCUIT_BREAKER_FAILURE_THRESHOLD: int = int(os.getenv("CIRCUIT_BREAKER_FAILURE_THRESHOLD", "5"))
|
||||
CIRCUIT_BREAKER_RESET_TIMEOUT: int = int(os.getenv("CIRCUIT_BREAKER_RESET_TIMEOUT", "300")) # 5 minutes
|
||||
|
||||
# ================================================================
|
||||
# CIRCUIT BREAKER SETTINGS - Enhanced with Pydantic validation
|
||||
# ================================================================
|
||||
|
||||
CIRCUIT_BREAKER_TIMEOUT_DURATION: int = Field(
|
||||
default=60,
|
||||
description="Seconds to wait before attempting recovery"
|
||||
)
|
||||
CIRCUIT_BREAKER_SUCCESS_THRESHOLD: int = Field(
|
||||
default=2,
|
||||
description="Successful calls needed to close circuit"
|
||||
)
|
||||
|
||||
# ================================================================
|
||||
# SAGA PATTERN SETTINGS
|
||||
# ================================================================
|
||||
|
||||
SAGA_TIMEOUT_SECONDS: int = Field(
|
||||
default=600,
|
||||
description="Timeout for saga execution (10 minutes)"
|
||||
)
|
||||
SAGA_ENABLE_COMPENSATION: bool = Field(
|
||||
default=True,
|
||||
description="Enable saga compensation on failure"
|
||||
)
|
||||
|
||||
# Service Integration URLs
|
||||
FORECASTING_SERVICE_URL: str = os.getenv("FORECASTING_SERVICE_URL", "http://forecasting-service:8000")
|
||||
PRODUCTION_SERVICE_URL: str = os.getenv("PRODUCTION_SERVICE_URL", "http://production-service:8000")
|
||||
PROCUREMENT_SERVICE_URL: str = os.getenv("PROCUREMENT_SERVICE_URL", "http://procurement-service:8000")
|
||||
NOTIFICATION_SERVICE_URL: str = os.getenv("NOTIFICATION_SERVICE_URL", "http://notification-service:8000")
|
||||
TENANT_SERVICE_URL: str = os.getenv("TENANT_SERVICE_URL", "http://tenant-service:8000")
|
||||
|
||||
# Notification Settings
|
||||
SEND_NOTIFICATIONS: bool = os.getenv("SEND_NOTIFICATIONS", "true").lower() == "true"
|
||||
NOTIFY_ON_SUCCESS: bool = os.getenv("NOTIFY_ON_SUCCESS", "true").lower() == "true"
|
||||
NOTIFY_ON_FAILURE: bool = os.getenv("NOTIFY_ON_FAILURE", "true").lower() == "true"
|
||||
|
||||
# Audit and Logging
|
||||
AUDIT_ORCHESTRATION_RUNS: bool = os.getenv("AUDIT_ORCHESTRATION_RUNS", "true").lower() == "true"
|
||||
DETAILED_LOGGING: bool = os.getenv("DETAILED_LOGGING", "true").lower() == "true"
|
||||
|
||||
|
||||
# Global settings instance
|
||||
settings = OrchestratorSettings()
|
||||
48
services/orchestrator/app/core/database.py
Normal file
48
services/orchestrator/app/core/database.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# ================================================================
|
||||
# services/orchestrator/app/core/database.py
|
||||
# ================================================================
|
||||
"""
|
||||
Database connection and session management for Orchestrator Service
|
||||
Minimal database - only for audit trail
|
||||
"""
|
||||
|
||||
from shared.database.base import DatabaseManager
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
from .config import settings
|
||||
|
||||
# Initialize database manager
|
||||
database_manager = DatabaseManager(
|
||||
database_url=settings.DATABASE_URL,
|
||||
echo=settings.DEBUG
|
||||
)
|
||||
|
||||
# Create async session factory
|
||||
AsyncSessionLocal = async_sessionmaker(
|
||||
database_manager.async_engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False,
|
||||
autocommit=False,
|
||||
autoflush=False,
|
||||
)
|
||||
|
||||
|
||||
async def get_db() -> AsyncSession:
|
||||
"""
|
||||
Dependency to get database session.
|
||||
Used in FastAPI endpoints via Depends(get_db).
|
||||
"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
try:
|
||||
yield session
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
|
||||
async def init_db():
|
||||
"""Initialize database (create tables if needed)"""
|
||||
await database_manager.create_all()
|
||||
|
||||
|
||||
async def close_db():
|
||||
"""Close database connections"""
|
||||
await database_manager.close()
|
||||
Reference in New Issue
Block a user