imporve features
This commit is contained in:
@@ -170,13 +170,49 @@ class EnhancedTenantService:
|
||||
await publish_tenant_created(str(tenant.id), owner_id, bakery_data.name)
|
||||
except Exception as e:
|
||||
logger.warning("Failed to publish tenant created event", error=str(e))
|
||||
|
||||
|
||||
# Automatically create location-context with city information
|
||||
# This is non-blocking - failure won't prevent tenant creation
|
||||
try:
|
||||
from shared.clients.external_client import ExternalServiceClient
|
||||
from shared.utils.city_normalization import normalize_city_id
|
||||
from app.core.config import settings
|
||||
|
||||
external_client = ExternalServiceClient(settings, "tenant-service")
|
||||
city_id = normalize_city_id(bakery_data.city)
|
||||
|
||||
if city_id:
|
||||
await external_client.create_tenant_location_context(
|
||||
tenant_id=str(tenant.id),
|
||||
city_id=city_id,
|
||||
notes="Auto-created during tenant registration"
|
||||
)
|
||||
logger.info(
|
||||
"Automatically created location-context",
|
||||
tenant_id=str(tenant.id),
|
||||
city_id=city_id
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Could not normalize city for location-context",
|
||||
tenant_id=str(tenant.id),
|
||||
city=bakery_data.city
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Failed to auto-create location-context (non-blocking)",
|
||||
tenant_id=str(tenant.id),
|
||||
city=bakery_data.city,
|
||||
error=str(e)
|
||||
)
|
||||
# Don't fail tenant creation if location-context creation fails
|
||||
|
||||
logger.info("Bakery created successfully",
|
||||
tenant_id=tenant.id,
|
||||
name=bakery_data.name,
|
||||
owner_id=owner_id,
|
||||
subdomain=tenant.subdomain)
|
||||
|
||||
|
||||
return TenantResponse.from_orm(tenant)
|
||||
|
||||
except (ValidationError, DuplicateRecordError) as e:
|
||||
|
||||
Reference in New Issue
Block a user