mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-13 03:30:46 +02:00
Update state_manager.py
This commit is contained in:
parent
c92c22cf04
commit
65ebf2032e
@ -409,32 +409,32 @@ class StateManager:
|
|||||||
if len(metrics_log) > MAX_HISTORY_ENTRIES:
|
if len(metrics_log) > MAX_HISTORY_ENTRIES:
|
||||||
metrics_log = metrics_log[-MAX_HISTORY_ENTRIES:]
|
metrics_log = metrics_log[-MAX_HISTORY_ENTRIES:]
|
||||||
|
|
||||||
def save_notifications(self, notifications):
|
def save_notifications(self, notifications):
|
||||||
"""Save notifications to persistent storage."""
|
"""Save notifications to persistent storage."""
|
||||||
try:
|
try:
|
||||||
# If we have Redis, use it
|
# If we have Redis, use it
|
||||||
if self.redis_client:
|
if self.redis_client:
|
||||||
notifications_json = json.dumps(notifications)
|
notifications_json = json.dumps(notifications)
|
||||||
self.redis_client.set("dashboard_notifications", notifications_json)
|
self.redis_client.set("dashboard_notifications", notifications_json)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
# Otherwise just keep in memory
|
# Otherwise just keep in memory
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error saving notifications: {e}")
|
logging.error(f"Error saving notifications: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_notifications(self):
|
def get_notifications(self):
|
||||||
"""Retrieve notifications from persistent storage."""
|
"""Retrieve notifications from persistent storage."""
|
||||||
try:
|
try:
|
||||||
# If we have Redis, use it
|
# If we have Redis, use it
|
||||||
if self.redis_client:
|
if self.redis_client:
|
||||||
notifications_json = self.redis_client.get("dashboard_notifications")
|
notifications_json = self.redis_client.get("dashboard_notifications")
|
||||||
if notifications_json:
|
if notifications_json:
|
||||||
return json.loads(notifications_json)
|
return json.loads(notifications_json)
|
||||||
|
|
||||||
# Return empty list if not found or no Redis
|
# Return empty list if not found or no Redis
|
||||||
return []
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error retrieving notifications: {e}")
|
logging.error(f"Error retrieving notifications: {e}")
|
||||||
return []
|
return []
|
||||||
|
Loading…
Reference in New Issue
Block a user