Fix some bugginess with how expired alerts and alert max_duration were handled. Closes #34

This commit is contained in:
Ian Renton
2025-10-08 16:09:39 +01:00
parent d7f9c36b28
commit e01b6d5ea9
7 changed files with 35 additions and 23 deletions

View File

@@ -1,9 +1,9 @@
import copy
import hashlib
import json
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timedelta
import copy
import pytz
from core.constants import DXCC_FLAGS
@@ -117,4 +117,12 @@ class Alert:
# JSON serialise
def to_json(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True)
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True)
# Decide if this alert has expired (in which case it should not be added to the system in the first place, and not
# returned by the web server if later requested, and removed by the cleanup functions. "Expired" is defined as
# either having an end_time in the past, or if it only has a start_time, then that start time was more than 3 hours
# ago. If it somehow doesn't have a start_time either, it is considered to be expired.
def expired(self):
return not self.start_time or (self.end_time and self.end_time < datetime.now(pytz.UTC).timestamp()) or (
not self.end_time and self.start_time < (datetime.now(pytz.UTC) - timedelta(hours=3)).timestamp())