First attempt at SSE backend #3

This commit is contained in:
Ian Renton
2025-12-22 12:04:35 +00:00
parent 968576f74c
commit c95c6bb347
7 changed files with 427 additions and 148 deletions

View File

@@ -3,6 +3,7 @@ from datetime import datetime
import pytz
from core.config import MAX_SPOT_AGE
from spothole import add_spot
# Generic spot provider class. Subclasses of this query the individual APIs for data.
@@ -32,23 +33,19 @@ class SpotProvider:
def submit_batch(self, spots):
for spot in spots:
if datetime.fromtimestamp(spot.time, pytz.UTC) > self.last_spot_time:
# Fill in any blanks
# Fill in any blanks and add to the list
spot.infer_missing()
# Add to the list, provided it heas not already expired.
if not spot.expired():
self.spots.add(spot.id, spot, expire=MAX_SPOT_AGE)
add_spot(spot)
self.last_spot_time = datetime.fromtimestamp(max(map(lambda s: s.time, spots)), pytz.UTC)
# Submit a single spot retrieved from the provider. This will be added to the list regardless of its age. Spots
# passing the check will also have their infer_missing() method called to complete their data set. This is called by
# the data streaming subclasses, which can be relied upon not to re-provide old spots.
def submit(self, spot):
# Fill in any blanks
# Fill in any blanks and add to the list
spot.infer_missing()
# Add to the list, provided it heas not already expired.
if not spot.expired():
self.spots.add(spot.id, spot, expire=MAX_SPOT_AGE)
self.last_spot_time = datetime.fromtimestamp(spot.time, pytz.UTC)
add_spot(spot)
self.last_spot_time = datetime.fromtimestamp(spot.time, pytz.UTC)
# Stop any threads and prepare for application shutdown
def stop(self):