Improve AI logic
This commit is contained in:
@@ -16,11 +16,11 @@ logger = structlog.get_logger()
|
||||
class NotificationServiceClient(BaseServiceClient):
|
||||
"""Client for communicating with the Notification Service"""
|
||||
|
||||
def __init__(self, config: BaseServiceSettings):
|
||||
super().__init__("notification", config)
|
||||
def __init__(self, config: BaseServiceSettings, calling_service_name: str = "unknown"):
|
||||
super().__init__(calling_service_name, config)
|
||||
|
||||
def get_service_base_path(self) -> str:
|
||||
return "/api/v1/notifications"
|
||||
return "/api/v1"
|
||||
|
||||
# ================================================================
|
||||
# NOTIFICATION ENDPOINTS
|
||||
@@ -64,7 +64,7 @@ class NotificationServiceClient(BaseServiceClient):
|
||||
"metadata": metadata or {}
|
||||
}
|
||||
|
||||
result = await self.post("send", data=notification_data, tenant_id=tenant_id)
|
||||
result = await self.post("notifications/send", data=notification_data, tenant_id=tenant_id)
|
||||
if result:
|
||||
logger.info("Notification sent successfully",
|
||||
tenant_id=tenant_id,
|
||||
@@ -110,6 +110,62 @@ class NotificationServiceClient(BaseServiceClient):
|
||||
priority=priority
|
||||
)
|
||||
|
||||
async def send_workflow_summary(
|
||||
self,
|
||||
tenant_id: str,
|
||||
notification_data: Dict[str, Any]
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Send workflow summary notification
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant ID
|
||||
notification_data: Summary data to include in notification
|
||||
|
||||
Returns:
|
||||
Dictionary with notification result
|
||||
"""
|
||||
try:
|
||||
# Prepare workflow summary notification
|
||||
subject = f"Daily Workflow Summary - {notification_data.get('orchestration_run_id', 'N/A')}"
|
||||
|
||||
message_parts = [
|
||||
f"Daily workflow completed for tenant {tenant_id}",
|
||||
f"Orchestration Run ID: {notification_data.get('orchestration_run_id', 'N/A')}",
|
||||
f"Forecasts created: {notification_data.get('forecasts_created', 0)}",
|
||||
f"Production batches created: {notification_data.get('batches_created', 0)}",
|
||||
f"Procurement requirements created: {notification_data.get('requirements_created', 0)}",
|
||||
f"Purchase orders created: {notification_data.get('pos_created', 0)}"
|
||||
]
|
||||
|
||||
message = "\n".join(message_parts)
|
||||
|
||||
notification_payload = {
|
||||
"type": "email",
|
||||
"message": message,
|
||||
"priority": "normal",
|
||||
"subject": subject,
|
||||
"metadata": {
|
||||
"orchestration_run_id": notification_data.get('orchestration_run_id'),
|
||||
"forecast_id": notification_data.get('forecast_id'),
|
||||
"production_schedule_id": notification_data.get('production_schedule_id'),
|
||||
"procurement_plan_id": notification_data.get('procurement_plan_id'),
|
||||
"summary_type": "workflow_completion"
|
||||
}
|
||||
}
|
||||
|
||||
result = await self.post("notifications/send", data=notification_payload, tenant_id=tenant_id)
|
||||
if result:
|
||||
logger.info("Workflow summary notification sent successfully",
|
||||
tenant_id=tenant_id,
|
||||
orchestration_run_id=notification_data.get('orchestration_run_id'))
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error("Error sending workflow summary notification",
|
||||
error=str(e),
|
||||
tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
# ================================================================
|
||||
# UTILITY METHODS
|
||||
# ================================================================
|
||||
|
||||
Reference in New Issue
Block a user