Disk-based caching for spots so they survive a software restart

This commit is contained in:
Ian Renton
2025-10-04 09:12:40 +01:00
parent bfcaf6e261
commit c785137258
5 changed files with 29 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timedelta
from datetime import datetime
from threading import Timer
from time import sleep
@@ -10,10 +10,9 @@ import pytz
class CleanupTimer:
# Constructor
def __init__(self, spot_list, cleanup_interval, max_spot_age):
self.spot_list = spot_list
def __init__(self, spots, cleanup_interval):
self.spots = spots
self.cleanup_interval = cleanup_interval
self.max_spot_age = max_spot_age
self.cleanup_timer = None
self.last_cleanup_time = datetime.min.replace(tzinfo=pytz.UTC)
self.status = "Starting"
@@ -30,10 +29,7 @@ class CleanupTimer:
def cleanup(self):
try:
# Perform cleanup
for spot in self.spot_list:
if not spot.time or spot.time < datetime.now(pytz.UTC) - timedelta(seconds=self.max_spot_age):
self.spot_list.remove(spot)
self.spots.expire()
self.status = "OK"
self.last_cleanup_time = datetime.now(pytz.UTC)