mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-11 07:01:41 +00:00
Improve slow startup times. #126
This commit is contained in:
+18
-18
@@ -1,3 +1,6 @@
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from core.config import config, create_provider_from_config
|
||||
|
||||
|
||||
@@ -27,27 +30,24 @@ class DataProviders:
|
||||
for entry in config.get("callsign_data_providers", []):
|
||||
self.callsign_data_providers.append(create_provider_from_config("providers.callsigndata", entry))
|
||||
|
||||
@staticmethod
|
||||
def start_providers(providers, type):
|
||||
"""Helper method to activate enabled providers in the list."""
|
||||
|
||||
logging.info(f"Starting %s providers...", type)
|
||||
for p in providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
def start(self):
|
||||
# Start data providers before spot/alert providers so the lookup data is there already for incoming spots.
|
||||
for p in self.static_data_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
for p in self.sig_ref_data_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
for p in self.callsign_data_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
for p in self.spot_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
for p in self.alert_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
for p in self.solar_condition_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
# Each category is fired off after a small delay to give the rest of Spothole chance to start up.
|
||||
threading.Timer(5.0, lambda: self.start_providers(self.static_data_providers, "static data")).start()
|
||||
threading.Timer(10.0, lambda: self.start_providers(self.callsign_data_providers, "callsign data")).start()
|
||||
threading.Timer(15.0, lambda: self.start_providers(self.spot_providers, "spot")).start()
|
||||
threading.Timer(20.0, lambda: self.start_providers(self.alert_providers, "alert")).start()
|
||||
threading.Timer(25.0, lambda: self.start_providers(self.solar_condition_providers, "solar condition")).start()
|
||||
threading.Timer(30.0, lambda: self.start_providers(self.sig_ref_data_providers, "SIG ref data")).start()
|
||||
|
||||
def stop(self):
|
||||
for sp in self.spot_providers:
|
||||
|
||||
Reference in New Issue
Block a user