mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Further alert implementation #17
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from threading import Timer
|
||||
from time import sleep
|
||||
|
||||
@@ -32,6 +32,17 @@ class CleanupTimer:
|
||||
# Perform cleanup
|
||||
self.spots.expire()
|
||||
self.alerts.expire()
|
||||
|
||||
# Alerts can persist in the system for a while, so we want to explicitly clean up any alerts that have
|
||||
# definitively ended, or if they have no definite end time, then if the start time was more than 24 hours
|
||||
# ago.
|
||||
for id in list(self.alerts.iterkeys()):
|
||||
alert = self.alerts[id]
|
||||
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.evict(id)
|
||||
|
||||
self.status = "OK"
|
||||
self.last_cleanup_time = datetime.now(pytz.UTC)
|
||||
|
||||
@@ -41,4 +52,4 @@ class CleanupTimer:
|
||||
sleep(1)
|
||||
|
||||
self.cleanup_timer = Timer(self.cleanup_interval, self.cleanup)
|
||||
self.cleanup_timer.start()
|
||||
self.cleanup_timer.start()
|
||||
|
||||
Reference in New Issue
Block a user