Initial commit - production deployment
This commit is contained in:
0
services/alert_processor/app/core/__init__.py
Normal file
0
services/alert_processor/app/core/__init__.py
Normal file
51
services/alert_processor/app/core/config.py
Normal file
51
services/alert_processor/app/core/config.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
Configuration settings for alert processor service.
|
||||
"""
|
||||
|
||||
import os
|
||||
from shared.config.base import BaseServiceSettings
|
||||
|
||||
|
||||
class Settings(BaseServiceSettings):
|
||||
"""Application settings"""
|
||||
|
||||
# Service info - override defaults
|
||||
SERVICE_NAME: str = "alert-processor"
|
||||
APP_NAME: str = "Alert Processor Service"
|
||||
DESCRIPTION: str = "Central alert and recommendation processor"
|
||||
VERSION: str = "2.0.0"
|
||||
|
||||
# Alert processor specific settings
|
||||
RABBITMQ_EXCHANGE: str = "events.exchange"
|
||||
RABBITMQ_QUEUE: str = "alert_processor.queue"
|
||||
REDIS_SSE_PREFIX: str = "alerts"
|
||||
ORCHESTRATOR_TIMEOUT: int = 10
|
||||
NOTIFICATION_TIMEOUT: int = 5
|
||||
CACHE_ENABLED: bool = True
|
||||
CACHE_TTL_SECONDS: int = 300
|
||||
|
||||
@property
|
||||
def NOTIFICATION_URL(self) -> str:
|
||||
"""Get notification service URL for backwards compatibility"""
|
||||
return self.NOTIFICATION_SERVICE_URL
|
||||
|
||||
# Database configuration (secure approach - build from components)
|
||||
@property
|
||||
def DATABASE_URL(self) -> str:
|
||||
"""Build database URL from secure components"""
|
||||
# Try complete URL first (for backward compatibility)
|
||||
complete_url = os.getenv("ALERT_PROCESSOR_DATABASE_URL")
|
||||
if complete_url:
|
||||
return complete_url
|
||||
|
||||
# Build from components (secure approach)
|
||||
user = os.getenv("ALERT_PROCESSOR_DB_USER", "alert_processor_user")
|
||||
password = os.getenv("ALERT_PROCESSOR_DB_PASSWORD", "alert_processor_pass123")
|
||||
host = os.getenv("ALERT_PROCESSOR_DB_HOST", "alert-processor-db-service")
|
||||
port = os.getenv("ALERT_PROCESSOR_DB_PORT", "5432")
|
||||
name = os.getenv("ALERT_PROCESSOR_DB_NAME", "alert_processor_db")
|
||||
|
||||
return f"postgresql+asyncpg://{user}:{password}@{host}:{port}/{name}"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
48
services/alert_processor/app/core/database.py
Normal file
48
services/alert_processor/app/core/database.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Database connection and session management for Alert Processor Service
|
||||
"""
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
from .config import settings
|
||||
|
||||
from shared.database.base import DatabaseManager
|
||||
|
||||
# Initialize database manager
|
||||
database_manager = DatabaseManager(
|
||||
database_url=settings.DATABASE_URL,
|
||||
service_name=settings.SERVICE_NAME,
|
||||
pool_size=settings.DB_POOL_SIZE,
|
||||
max_overflow=settings.DB_MAX_OVERFLOW,
|
||||
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