Improve the frontend
This commit is contained in:
@@ -55,14 +55,14 @@ class NotificationServiceClient(BaseServiceClient):
|
||||
"""Send notification via notification service"""
|
||||
try:
|
||||
response = await self.post(
|
||||
"/api/v1/notifications/send",
|
||||
json={
|
||||
"notifications/send",
|
||||
data={
|
||||
"tenant_id": tenant_id,
|
||||
"notification": notification,
|
||||
"channels": channels
|
||||
}
|
||||
)
|
||||
return response
|
||||
return response if response else {"status": "failed", "error": "No response from notification service"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to send notification", error=str(e), tenant_id=tenant_id)
|
||||
return {"status": "failed", "error": str(e)}
|
||||
@@ -187,8 +187,8 @@ class AlertProcessorService:
|
||||
},
|
||||
channels=channels
|
||||
)
|
||||
|
||||
if notification_result.get('status') == 'success':
|
||||
|
||||
if notification_result and notification_result.get('status') == 'success':
|
||||
self.notifications_sent += 1
|
||||
|
||||
# Stream to SSE for real-time dashboard (always)
|
||||
@@ -255,16 +255,27 @@ class AlertProcessorService:
|
||||
return alert_dict
|
||||
|
||||
async def _cache_active_alerts(self, tenant_id: str):
|
||||
"""Cache all active alerts for a tenant in Redis for quick SSE access"""
|
||||
"""
|
||||
Cache today's active alerts for a tenant in Redis for quick SSE access
|
||||
|
||||
Only caches alerts from today (00:00 UTC onwards) to avoid flooding
|
||||
the dashboard with historical alerts on initial connection.
|
||||
Analytics endpoints should query the database directly for historical data.
|
||||
"""
|
||||
try:
|
||||
from app.models.alerts import Alert, AlertStatus
|
||||
from sqlalchemy import select
|
||||
|
||||
async with self.db_manager.get_session() as session:
|
||||
# Query all active alerts for this tenant
|
||||
# Calculate start of today (UTC) to filter only today's alerts
|
||||
today_start = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
# Query only today's active alerts for this tenant
|
||||
# This prevents showing yesterday's alerts on dashboard initial load
|
||||
query = select(Alert).where(
|
||||
Alert.tenant_id == tenant_id,
|
||||
Alert.status == AlertStatus.ACTIVE
|
||||
Alert.status == AlertStatus.ACTIVE,
|
||||
Alert.created_at >= today_start # Only today's alerts
|
||||
).order_by(Alert.created_at.desc()).limit(50)
|
||||
|
||||
result = await session.execute(query)
|
||||
@@ -294,9 +305,10 @@ class AlertProcessorService:
|
||||
json.dumps(active_items)
|
||||
)
|
||||
|
||||
logger.debug("Cached active alerts in Redis",
|
||||
logger.debug("Cached today's active alerts in Redis",
|
||||
tenant_id=tenant_id,
|
||||
count=len(active_items))
|
||||
count=len(active_items),
|
||||
filter_date=today_start.isoformat())
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to cache active alerts",
|
||||
|
||||
Reference in New Issue
Block a user