mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Disk-based caching for spots so they survive a software restart
This commit is contained in:
24
spothole.py
24
spothole.py
@@ -9,24 +9,16 @@ from time import sleep
|
||||
import importlib
|
||||
import psutil
|
||||
import pytz
|
||||
from diskcache import Cache
|
||||
|
||||
from core.cleanup import CleanupTimer
|
||||
from core.config import config, MAX_SPOT_AGE, WEB_SERVER_PORT, SERVER_OWNER_CALLSIGN
|
||||
from core.constants import SOFTWARE_VERSION
|
||||
from providers.aprsis import APRSIS
|
||||
from providers.dxcluster import DXCluster
|
||||
from providers.gma import GMA
|
||||
from providers.hema import HEMA
|
||||
from providers.parksnpeaks import ParksNPeaks
|
||||
from providers.pota import POTA
|
||||
from providers.rbn import RBN
|
||||
from providers.sota import SOTA
|
||||
from providers.wwbota import WWBOTA
|
||||
from providers.wwff import WWFF
|
||||
from core.utils import QRZ_CALLSIGN_DATA_CACHE
|
||||
from server.webserver import WebServer
|
||||
|
||||
# Globals
|
||||
spot_list = []
|
||||
spots = Cache('.spots_cache')
|
||||
status_data = {}
|
||||
providers = []
|
||||
cleanup_timer = None
|
||||
@@ -41,6 +33,8 @@ def shutdown(sig, frame):
|
||||
if p.enabled:
|
||||
p.stop()
|
||||
cleanup_timer.stop()
|
||||
QRZ_CALLSIGN_DATA_CACHE.close()
|
||||
spots.close()
|
||||
|
||||
# Utility method to get a data provider based on the class specified in its config entry.
|
||||
def get_provider_from_config(config_providers_entry):
|
||||
@@ -71,18 +65,18 @@ if __name__ == '__main__':
|
||||
for entry in config["providers"]:
|
||||
providers.append(get_provider_from_config(entry))
|
||||
# Set up data providers
|
||||
for p in providers: p.setup(spot_list=spot_list)
|
||||
for p in providers: p.setup(spots=spots)
|
||||
# Start data providers
|
||||
for p in providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
# Set up timer to clear spot list of old data
|
||||
cleanup_timer = CleanupTimer(spot_list=spot_list, cleanup_interval=60, max_spot_age=MAX_SPOT_AGE)
|
||||
cleanup_timer = CleanupTimer(spots=spots, cleanup_interval=60)
|
||||
cleanup_timer.start()
|
||||
|
||||
# Set up web server
|
||||
web_server = WebServer(spot_list=spot_list, status_data=status_data, port=WEB_SERVER_PORT)
|
||||
web_server = WebServer(spots=spots, status_data=status_data, port=WEB_SERVER_PORT)
|
||||
web_server.start()
|
||||
|
||||
logging.info("Startup complete.")
|
||||
@@ -92,7 +86,7 @@ if __name__ == '__main__':
|
||||
sleep(5)
|
||||
status_data["uptime"] = str(datetime.now(pytz.UTC) - startup_time).split(".")[0]
|
||||
status_data["mem_use_mb"] = round(psutil.Process(os.getpid()).memory_info().rss / (1024 * 1024), 3)
|
||||
status_data["num_spots"] = len(spot_list)
|
||||
status_data["num_spots"] = len(spots)
|
||||
status_data["providers"] = list(map(lambda p: {"name": p.name, "enabled": p.enabled, "status": p.status, "last_updated": p.last_update_time, "last_spot": p.last_spot_time}, providers))
|
||||
status_data["cleanup"] = {"status": cleanup_timer.status, "last_ran": cleanup_timer.last_cleanup_time}
|
||||
status_data["webserver"] = {"status": web_server.status, "last_api_access": web_server.last_api_access_time, "last_page_access": web_server.last_page_access_time}
|
||||
|
||||
Reference in New Issue
Block a user