Add DEMO feature to the project
This commit is contained in:
@@ -11,6 +11,7 @@ import structlog
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
|
||||
from shared.alerts.base_service import BaseAlertService, AlertServiceMixin
|
||||
from shared.database.base import create_database_manager
|
||||
from app.services.procurement_service import ProcurementService
|
||||
|
||||
logger = structlog.get_logger()
|
||||
@@ -204,10 +205,44 @@ class ProcurementSchedulerService(BaseAlertService, AlertServiceMixin):
|
||||
logger.error("💥 Stale plan cleanup failed", error=str(e))
|
||||
|
||||
async def get_active_tenants(self) -> List[UUID]:
|
||||
"""Get active tenants from tenant service or base implementation"""
|
||||
# Only use tenant service, no fallbacks
|
||||
"""Get active tenants from tenant service, excluding demo tenants"""
|
||||
try:
|
||||
return await super().get_active_tenants()
|
||||
all_tenants = await super().get_active_tenants()
|
||||
|
||||
# Filter out demo tenants
|
||||
from services.tenant.app.models.tenants import Tenant
|
||||
from sqlalchemy import select
|
||||
import os
|
||||
|
||||
tenant_db_url = os.getenv("TENANT_DATABASE_URL")
|
||||
if not tenant_db_url:
|
||||
logger.warning("TENANT_DATABASE_URL not set, returning all tenants")
|
||||
return all_tenants
|
||||
|
||||
tenant_db = create_database_manager(tenant_db_url, "tenant-filter")
|
||||
non_demo_tenants = []
|
||||
|
||||
async with tenant_db.get_session() as session:
|
||||
for tenant_id in all_tenants:
|
||||
result = await session.execute(
|
||||
select(Tenant).where(Tenant.id == tenant_id)
|
||||
)
|
||||
tenant = result.scalars().first()
|
||||
|
||||
# Only include non-demo tenants
|
||||
if tenant and not tenant.is_demo:
|
||||
non_demo_tenants.append(tenant_id)
|
||||
elif tenant and tenant.is_demo:
|
||||
logger.debug("Excluding demo tenant from procurement scheduler",
|
||||
tenant_id=str(tenant_id))
|
||||
|
||||
logger.info("Filtered demo tenants from procurement scheduling",
|
||||
total_tenants=len(all_tenants),
|
||||
non_demo_tenants=len(non_demo_tenants),
|
||||
demo_tenants_filtered=len(all_tenants) - len(non_demo_tenants))
|
||||
|
||||
return non_demo_tenants
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Could not fetch tenants from base service", error=str(e))
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user