Add improvements 2
This commit is contained in:
@@ -29,16 +29,15 @@ class DataClient:
|
||||
self.sales_client = get_sales_client(settings, "training")
|
||||
self.external_client = get_external_client(settings, "training")
|
||||
|
||||
# ExternalServiceClient always has get_stored_traffic_data_for_training method
|
||||
self.supports_stored_traffic_data = True
|
||||
|
||||
# Configure timeouts for HTTP clients
|
||||
self._configure_timeouts()
|
||||
|
||||
# Initialize circuit breakers for external services
|
||||
self._init_circuit_breakers()
|
||||
|
||||
# Check if the new method is available for stored traffic data
|
||||
if hasattr(self.external_client, 'get_stored_traffic_data_for_training'):
|
||||
self.supports_stored_traffic_data = True
|
||||
|
||||
def _configure_timeouts(self):
|
||||
"""Configure appropriate timeouts for HTTP clients"""
|
||||
timeout = httpx.Timeout(
|
||||
@@ -49,14 +48,12 @@ class DataClient:
|
||||
)
|
||||
|
||||
# Apply timeout to clients if they have httpx clients
|
||||
# Note: BaseServiceClient manages its own HTTP client internally
|
||||
if hasattr(self.sales_client, 'client') and isinstance(self.sales_client.client, httpx.AsyncClient):
|
||||
self.sales_client.client.timeout = timeout
|
||||
|
||||
if hasattr(self.external_client, 'client') and isinstance(self.external_client.client, httpx.AsyncClient):
|
||||
self.external_client.client.timeout = timeout
|
||||
else:
|
||||
self.supports_stored_traffic_data = False
|
||||
logger.warning("Stored traffic data method not available in external client")
|
||||
|
||||
def _init_circuit_breakers(self):
|
||||
"""Initialize circuit breakers for external service calls"""
|
||||
|
||||
@@ -404,22 +404,32 @@ class TrainingDataOrchestrator:
|
||||
tenant_id: str
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Collect POI features for bakery location.
|
||||
Collect POI features for bakery location (non-blocking).
|
||||
|
||||
POI features are static (location-based, not time-varying).
|
||||
This method is non-blocking with a short timeout to prevent training delays.
|
||||
If POI detection hasn't been run yet, training continues without POI features.
|
||||
|
||||
Returns:
|
||||
Dictionary with POI features or empty dict if unavailable
|
||||
"""
|
||||
try:
|
||||
logger.info(
|
||||
"Collecting POI features",
|
||||
"Collecting POI features (non-blocking)",
|
||||
tenant_id=tenant_id,
|
||||
location=(lat, lon)
|
||||
)
|
||||
|
||||
poi_features = await self.poi_feature_integrator.fetch_poi_features(
|
||||
tenant_id=tenant_id,
|
||||
latitude=lat,
|
||||
longitude=lon,
|
||||
force_refresh=False
|
||||
# Set a short timeout to prevent blocking training
|
||||
# POI detection should have been triggered during tenant registration
|
||||
poi_features = await asyncio.wait_for(
|
||||
self.poi_feature_integrator.fetch_poi_features(
|
||||
tenant_id=tenant_id,
|
||||
latitude=lat,
|
||||
longitude=lon,
|
||||
force_refresh=False
|
||||
),
|
||||
timeout=15.0 # 15 second timeout - POI should be cached from registration
|
||||
)
|
||||
|
||||
if poi_features:
|
||||
@@ -430,18 +440,24 @@ class TrainingDataOrchestrator:
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"No POI features collected (service may be unavailable)",
|
||||
"No POI features collected (service may be unavailable or not yet detected)",
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
|
||||
return poi_features or {}
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning(
|
||||
"POI collection timeout (15s) - continuing training without POI features. "
|
||||
"POI detection should be triggered during tenant registration for best results.",
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
return {}
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Failed to collect POI features, continuing without them",
|
||||
logger.warning(
|
||||
"Failed to collect POI features (non-blocking) - continuing training without them",
|
||||
tenant_id=tenant_id,
|
||||
error=str(e),
|
||||
exc_info=True
|
||||
error=str(e)
|
||||
)
|
||||
return {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user