New alert service
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Alembic environment configuration for alert-processor service"""
|
||||
"""Alembic environment configuration for alert_processor service"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
@@ -20,7 +20,6 @@ if shared_path not in sys.path:
|
||||
sys.path.insert(0, shared_path)
|
||||
|
||||
try:
|
||||
from app.config import AlertProcessorConfig
|
||||
from shared.database.base import Base
|
||||
|
||||
# Import all models to ensure they are registered with Base.metadata
|
||||
@@ -35,12 +34,12 @@ except ImportError as e:
|
||||
config = context.config
|
||||
|
||||
# Determine service name from file path
|
||||
service_name = "alert-processor"
|
||||
service_name_upper = "ALERT_PROCESSOR"
|
||||
service_name = os.path.basename(os.path.dirname(os.path.dirname(__file__)))
|
||||
service_name_upper = service_name.upper().replace('-', '_')
|
||||
|
||||
# Set database URL from environment variables with multiple fallback strategies
|
||||
database_url = (
|
||||
os.getenv('ALERT_PROCESSOR_DATABASE_URL') or # Service-specific
|
||||
os.getenv(f'{service_name_upper}_DATABASE_URL') or # Service-specific
|
||||
os.getenv('DATABASE_URL') # Generic fallback
|
||||
)
|
||||
|
||||
@@ -56,18 +55,18 @@ if not database_url:
|
||||
if all([postgres_host, postgres_db, postgres_user, postgres_password]):
|
||||
database_url = f"postgresql+asyncpg://{postgres_user}:{postgres_password}@{postgres_host}:{postgres_port}/{postgres_db}"
|
||||
else:
|
||||
# Try service-specific environment variables (alert-processor specific pattern)
|
||||
db_host = os.getenv('ALERT_PROCESSOR_DB_HOST', 'alert-processor-db-service')
|
||||
db_port = os.getenv('ALERT_PROCESSOR_DB_PORT', '5432')
|
||||
db_name = os.getenv('ALERT_PROCESSOR_DB_NAME', 'alert_processor_db')
|
||||
db_user = os.getenv('ALERT_PROCESSOR_DB_USER', 'alert_processor_user')
|
||||
db_password = os.getenv('ALERT_PROCESSOR_DB_PASSWORD')
|
||||
# Try service-specific environment variables
|
||||
db_host = os.getenv(f'{service_name_upper}_DB_HOST', f'{service_name}-db-service')
|
||||
db_port = os.getenv(f'{service_name_upper}_DB_PORT', '5432')
|
||||
db_name = os.getenv(f'{service_name_upper}_DB_NAME', f'{service_name.replace("-", "_")}_db')
|
||||
db_user = os.getenv(f'{service_name_upper}_DB_USER', f'{service_name.replace("-", "_")}_user')
|
||||
db_password = os.getenv(f'{service_name_upper}_DB_PASSWORD')
|
||||
|
||||
if db_password:
|
||||
database_url = f"postgresql+asyncpg://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
|
||||
|
||||
if not database_url:
|
||||
error_msg = "ERROR: No database URL configured for alert-processor service"
|
||||
error_msg = f"ERROR: No database URL configured for {service_name} service"
|
||||
print(error_msg)
|
||||
raise Exception(error_msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user