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

@@ -3,7 +3,7 @@ from datetime import datetime
import pytz
from core.constants import SOFTWARE_NAME, SOFTWARE_VERSION
from core.config import config, SERVER_OWNER_CALLSIGN
from core.config import config, SERVER_OWNER_CALLSIGN, MAX_SPOT_AGE
# Generic data provider class. Subclasses of this query the individual APIs for data.
@@ -19,11 +19,11 @@ class Provider:
self.last_update_time = datetime.min.replace(tzinfo=pytz.UTC)
self.last_spot_time = datetime.min.replace(tzinfo=pytz.UTC)
self.status = "Not Started" if self.enabled else "Disabled"
self.spot_list = None
self.spots = None
# Set up the provider, e.g. giving it the spot list to work from
def setup(self, spot_list):
self.spot_list = spot_list
def setup(self, spots):
self.spots = spots
# Start the provider. This should return immediately after spawning threads to access the remote resources
def start(self):
@@ -38,8 +38,8 @@ class Provider:
if spot.time > self.last_spot_time:
# Fill in any blanks
spot.infer_missing()
# Append to the list
self.spot_list.append(spot)
# Add to the list
self.spots.add(spot.guid, spot, expire=MAX_SPOT_AGE)
self.last_spot_time = max(map(lambda s: s.time, spots))
# Submit a single spot retrieved from the provider. This will be added to the list regardless of its age. Spots
@@ -48,8 +48,8 @@ class Provider:
def submit(self, spot):
# Fill in any blanks
spot.infer_missing()
# Append to the list
self.spot_list.append(spot)
# Add to the list
self.spots.add(spot.guid, spot, expire=MAX_SPOT_AGE)
self.last_spot_time = spot.time
# Stop any threads and prepare for application shutdown