Further alert implementation #17

This commit is contained in:
Ian Renton
2025-10-06 21:06:54 +01:00
parent e0675a01f0
commit 6ee4fe288a
14 changed files with 171 additions and 67 deletions

View File

@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
import pytz
@@ -35,8 +35,12 @@ class AlertProvider:
for alert in alerts:
# Fill in any blanks
alert.infer_missing()
# Add to the list
self.alerts.add(alert.id, alert, expire=MAX_ALERT_AGE)
# Add to the list, provided it meets the semsible date test. If alerts have an end time, it must be in the
# future, or if not, then the start date must be at least in the last 24 hours.
if (alert.end_time and alert.end_time > datetime.now(pytz.UTC).timestamp()) or (
not alert.end_time and alert.start_time > (datetime.now(
pytz.UTC) - timedelta(days=1)).timestamp()):
self.alerts.add(alert.id, alert, expire=MAX_ALERT_AGE)
# Stop any threads and prepare for application shutdown
def stop(self):