Fix startup issues
This commit is contained in:
@@ -46,7 +46,25 @@ class BaseAlertService:
|
||||
"""Initialize all detection mechanisms"""
|
||||
try:
|
||||
# Connect to Redis for leader election and deduplication
|
||||
self.redis = await Redis.from_url(self.config.REDIS_URL)
|
||||
import os
|
||||
redis_password = os.getenv('REDIS_PASSWORD', '')
|
||||
redis_host = os.getenv('REDIS_HOST', 'redis-service')
|
||||
redis_port = int(os.getenv('REDIS_PORT', '6379'))
|
||||
|
||||
# Create Redis client with explicit password parameter
|
||||
if redis_password:
|
||||
self.redis = await Redis(
|
||||
host=redis_host,
|
||||
port=redis_port,
|
||||
password=redis_password,
|
||||
decode_responses=True
|
||||
)
|
||||
else:
|
||||
self.redis = await Redis(
|
||||
host=redis_host,
|
||||
port=redis_port,
|
||||
decode_responses=True
|
||||
)
|
||||
logger.info("Connected to Redis", service=self.config.SERVICE_NAME)
|
||||
|
||||
# Connect to RabbitMQ
|
||||
@@ -98,7 +116,11 @@ class BaseAlertService:
|
||||
"""Leader election for scheduled jobs"""
|
||||
lock_key = f"scheduler_lock:{self.config.SERVICE_NAME}"
|
||||
lock_ttl = 60
|
||||
|
||||
|
||||
logger.info("DEBUG: maintain_leadership starting",
|
||||
service=self.config.SERVICE_NAME,
|
||||
redis_client_type=str(type(self.redis)))
|
||||
|
||||
while True:
|
||||
try:
|
||||
instance_id = getattr(self.config, 'INSTANCE_ID', str(uuid.uuid4()))
|
||||
@@ -161,7 +183,12 @@ class BaseAlertService:
|
||||
await asyncio.sleep(lock_ttl // 2 + random.uniform(0, 2))
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Leadership error", service=self.config.SERVICE_NAME, error=str(e))
|
||||
import traceback
|
||||
logger.error("Leadership error",
|
||||
service=self.config.SERVICE_NAME,
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
traceback=traceback.format_exc())
|
||||
self.is_leader = False
|
||||
await asyncio.sleep(5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user