REFACTOR - Database logic

This commit is contained in:
Urtzi Alfaro
2025-08-08 09:08:41 +02:00
parent 0154365bfc
commit 488bb3ef93
113 changed files with 22842 additions and 6503 deletions

View File

@@ -149,4 +149,67 @@ async def publish_forecasts_deleted_event(tenant_id: str, deletion_stats: Dict[s
}
)
except Exception as e:
logger.error("Failed to publish forecasts deletion event", error=str(e))
logger.error("Failed to publish forecasts deletion event", error=str(e))
# Additional publishing functions for compatibility
async def publish_forecast_generated(data: dict) -> bool:
"""Publish forecast generated event"""
try:
if rabbitmq_client:
await rabbitmq_client.publish_event(
exchange="forecasting_events",
routing_key="forecast.generated",
message=data
)
return True
except Exception as e:
logger.error("Failed to publish forecast generated event", error=str(e))
return False
async def publish_batch_forecast_completed(data: dict) -> bool:
"""Publish batch forecast completed event"""
try:
if rabbitmq_client:
await rabbitmq_client.publish_event(
exchange="forecasting_events",
routing_key="forecast.batch.completed",
message=data
)
return True
except Exception as e:
logger.error("Failed to publish batch forecast event", error=str(e))
return False
async def publish_forecast_alert(data: dict) -> bool:
"""Publish forecast alert event"""
try:
if rabbitmq_client:
await rabbitmq_client.publish_event(
exchange="forecasting_events",
routing_key="forecast.alert",
message=data
)
return True
except Exception as e:
logger.error("Failed to publish forecast alert event", error=str(e))
return False
# Publisher class for compatibility
class ForecastingStatusPublisher:
"""Publisher for forecasting status events"""
async def publish_status(self, status: str, data: dict) -> bool:
"""Publish forecasting status"""
try:
if rabbitmq_client:
await rabbitmq_client.publish_event(
exchange="forecasting_events",
routing_key=f"forecast.status.{status}",
message=data
)
return True
except Exception as e:
logger.error(f"Failed to publish {status} status", error=str(e))
return False