Add new infra architecture

This commit is contained in:
Urtzi Alfaro
2026-01-19 11:55:17 +01:00
parent 21d35ea92b
commit 35f164f0cd
311 changed files with 13241 additions and 3700 deletions

View File

@@ -156,21 +156,14 @@ class DeliveryTrackingService:
async def _check_all_tenants(self):
"""
Check deliveries for all active tenants (with leader election).
Check deliveries for all active tenants.
Only one pod executes this - others skip if not leader.
This method is only called by the leader pod (via APScheduler).
Leader election is handled at the scheduler level, not here.
"""
# Try to acquire leader lock
if not await self._try_acquire_leader_lock():
logger.debug(
"Skipping delivery check - not leader",
instance_id=self.instance_id
)
return
logger.info("Starting delivery checks", instance_id=self.instance_id)
try:
logger.info("Starting delivery checks (as leader)", instance_id=self.instance_id)
# Get all active tenants from database
tenants = await self._get_active_tenants()
@@ -194,24 +187,8 @@ class DeliveryTrackingService:
total_alerts=total_alerts
)
finally:
await self._release_leader_lock()
async def _try_acquire_leader_lock(self) -> bool:
"""
Try to acquire leader lock for delivery tracking.
Uses Redis to ensure only one pod runs checks.
Returns True if acquired, False if another pod is leader.
"""
# This simplified version doesn't implement leader election
# In a real implementation, you'd use Redis or database locks
logger.info("Delivery tracking check running", instance_id=self.instance_id)
return True
async def _release_leader_lock(self):
"""Release leader lock"""
logger.debug("Delivery tracking check completed", instance_id=self.instance_id)
except Exception as e:
logger.error("Delivery checks failed", error=str(e), exc_info=True)
async def _get_active_tenants(self) -> List[UUID]:
"""