New alert service

This commit is contained in:
Urtzi Alfaro
2025-12-05 20:07:01 +01:00
parent 1fe3a73549
commit 667e6e0404
393 changed files with 26002 additions and 61033 deletions

View File

@@ -7,7 +7,7 @@ from fastapi import FastAPI
from sqlalchemy import text
from app.core.config import settings
from app.core.database import database_manager
from app.api import tenants, tenant_members, tenant_operations, webhooks, internal_demo, plans, subscription, tenant_settings, whatsapp_admin, usage_forecast, enterprise_upgrade, tenant_locations
from app.api import tenants, tenant_members, tenant_operations, webhooks, internal_demo, plans, subscription, tenant_settings, whatsapp_admin, usage_forecast, enterprise_upgrade, tenant_locations, tenant_hierarchy
from shared.service_base import StandardFastAPIService
@@ -71,10 +71,30 @@ class TenantService(StandardFastAPIService):
from app.models.tenant_settings import TenantSettings
self.logger.info("Tenant models imported successfully")
# Initialize Redis
from shared.redis_utils import initialize_redis, get_redis_client
await initialize_redis(settings.REDIS_URL, db=settings.REDIS_DB, max_connections=20)
redis_client = await get_redis_client()
self.logger.info("Redis initialized successfully")
# Start usage tracking scheduler
from app.jobs.usage_tracking_scheduler import start_scheduler
await start_scheduler(self.database_manager, redis_client, settings)
self.logger.info("Usage tracking scheduler started")
async def on_shutdown(self, app: FastAPI):
"""Custom shutdown logic for tenant service"""
# Stop usage tracking scheduler
from app.jobs.usage_tracking_scheduler import stop_scheduler
await stop_scheduler()
self.logger.info("Usage tracking scheduler stopped")
# Close Redis connection
from shared.redis_utils import close_redis
await close_redis()
self.logger.info("Redis connection closed")
# Database cleanup is handled by the base class
pass
def get_service_features(self):
"""Return tenant-specific features"""
@@ -124,6 +144,7 @@ service.add_router(tenant_operations.router, tags=["tenant-operations"])
service.add_router(webhooks.router, tags=["webhooks"])
service.add_router(enterprise_upgrade.router, tags=["enterprise"]) # Enterprise tier upgrade endpoints
service.add_router(tenant_locations.router, tags=["tenant-locations"]) # Tenant locations endpoints
service.add_router(tenant_hierarchy.router, tags=["tenant-hierarchy"]) # Tenant hierarchy endpoints
service.add_router(internal_demo.router, tags=["internal"])
if __name__ == "__main__":