mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Refactor of caching & data storage part 3 #118
This commit is contained in:
+17
-26
@@ -1,11 +1,11 @@
|
||||
# Main script
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
|
||||
from core.config import config, SERVER_OWNER_CALLSIGN, LOG_LEVEL
|
||||
from core.config import config, SERVER_OWNER_CALLSIGN, LOG_LEVEL, get_sig_ref_data_provider_from_config, \
|
||||
get_spot_provider_from_config, get_alert_provider_from_config, get_solar_conditions_provider_from_config
|
||||
from core.constants import SOFTWARE_VERSION
|
||||
from core.data_store import DATA_STORE
|
||||
from core.lookup_helper import lookup_helper
|
||||
@@ -17,6 +17,7 @@ web_server = None
|
||||
spot_providers = []
|
||||
alert_providers = []
|
||||
solar_condition_providers = []
|
||||
sig_ref_data_providers = []
|
||||
cleanup_timer = None
|
||||
run = True
|
||||
|
||||
@@ -38,34 +39,13 @@ def shutdown(_signum=None, _frame=None):
|
||||
for scp in solar_condition_providers:
|
||||
if scp.enabled:
|
||||
scp.stop()
|
||||
for srdp in sig_ref_data_providers:
|
||||
if srdp.enabled:
|
||||
srdp.stop()
|
||||
DATA_STORE.close()
|
||||
os._exit(0)
|
||||
|
||||
|
||||
def get_spot_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get a spot provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('spotproviders.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
|
||||
def get_alert_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get an alert provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('alertproviders.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
|
||||
def get_solar_conditions_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get a solar conditions provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('solarconditionsproviders.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
|
||||
# Main function
|
||||
if __name__ == '__main__':
|
||||
# Set up logging
|
||||
@@ -85,6 +65,9 @@ if __name__ == '__main__':
|
||||
# Shut down gracefully on SIGINT
|
||||
signal.signal(signal.SIGINT, shutdown)
|
||||
|
||||
# Set up data store
|
||||
DATA_STORE.setup()
|
||||
|
||||
# Set up lookup helper
|
||||
lookup_helper.start()
|
||||
|
||||
@@ -112,9 +95,17 @@ if __name__ == '__main__':
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
# Fetch, set up and start SIG reference data providers
|
||||
for entry in config.get("sig-ref-data-providers", []):
|
||||
sig_ref_data_providers.append(get_sig_ref_data_provider_from_config(entry))
|
||||
for p in sig_ref_data_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
# Set up status reporter
|
||||
status_reporter = StatusReporter(web_server=web_server, spot_providers=spot_providers,
|
||||
alert_providers=alert_providers,
|
||||
sig_ref_data_providers=sig_ref_data_providers,
|
||||
solar_condition_providers=solar_condition_providers, run_interval=5)
|
||||
status_reporter.start()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user