mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Refactor of caching & data storage part 10 #118
This commit is contained in:
+16
-74
@@ -4,49 +4,25 @@ import os
|
||||
import signal
|
||||
import sys
|
||||
|
||||
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, \
|
||||
get_static_data_provider_from_config
|
||||
from core.constants import SOFTWARE_VERSION
|
||||
from core.data_store import DATA_STORE
|
||||
from core.call_lookup_helper import lookup_helper
|
||||
from core.config import SERVER_OWNER_CALLSIGN, LOG_LEVEL
|
||||
from core.constants import SOFTWARE_VERSION
|
||||
from core.data_providers import DATA_PROVIDERS
|
||||
from core.data_store import DATA_STORE
|
||||
from core.status_reporter import StatusReporter
|
||||
from server.webserver import WebServer
|
||||
from server.webserver import WEB_SERVER
|
||||
|
||||
# Globals
|
||||
web_server = None
|
||||
spot_providers = []
|
||||
alert_providers = []
|
||||
solar_condition_providers = []
|
||||
static_data_providers = []
|
||||
sig_ref_data_providers = []
|
||||
cleanup_timer = None
|
||||
run = True
|
||||
|
||||
|
||||
def shutdown(_signum=None, _frame=None):
|
||||
"""Shutdown function"""
|
||||
|
||||
global run
|
||||
|
||||
logging.info("Stopping program...")
|
||||
if web_server:
|
||||
web_server.stop()
|
||||
for sp in spot_providers:
|
||||
if sp.enabled:
|
||||
sp.stop()
|
||||
for ap in alert_providers:
|
||||
if ap.enabled:
|
||||
ap.stop()
|
||||
for scp in solar_condition_providers:
|
||||
if scp.enabled:
|
||||
scp.stop()
|
||||
for srdp in sig_ref_data_providers:
|
||||
if srdp.enabled:
|
||||
srdp.stop()
|
||||
for srdp in static_data_providers:
|
||||
if srdp.enabled:
|
||||
srdp.stop()
|
||||
WEB_SERVER.stop()
|
||||
DATA_PROVIDERS.stop()
|
||||
DATA_STORE.close()
|
||||
os._exit(0)
|
||||
|
||||
@@ -76,54 +52,20 @@ if __name__ == '__main__':
|
||||
# Set up lookup helper
|
||||
lookup_helper.start()
|
||||
|
||||
# Set up web server
|
||||
web_server = WebServer()
|
||||
# Set up and start data providers
|
||||
DATA_PROVIDERS.setup()
|
||||
DATA_PROVIDERS.start()
|
||||
|
||||
# Fetch, set up and start spot providers
|
||||
for entry in config["spot-providers"]:
|
||||
spot_providers.append(get_spot_provider_from_config(entry))
|
||||
for p in spot_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
# Fetch, set up and start alert providers
|
||||
for entry in config["alert-providers"]:
|
||||
alert_providers.append(get_alert_provider_from_config(entry))
|
||||
for p in alert_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
# Fetch, set up and start solar conditions providers
|
||||
for entry in config.get("solar-condition-providers", []):
|
||||
solar_condition_providers.append(get_solar_conditions_provider_from_config(entry))
|
||||
for p in solar_condition_providers:
|
||||
if p.enabled:
|
||||
p.start()
|
||||
|
||||
# Fetch, set up and start static reference data providers
|
||||
for entry in config.get("static-data-providers", []):
|
||||
static_data_providers.append(get_static_data_provider_from_config(entry))
|
||||
for p in static_data_providers:
|
||||
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, static_data_providers=static_data_providers,
|
||||
sig_ref_data_providers=sig_ref_data_providers,
|
||||
solar_condition_providers=solar_condition_providers, run_interval=5)
|
||||
# Set up and start status reporter
|
||||
status_reporter = StatusReporter(run_interval=5)
|
||||
status_reporter.start()
|
||||
|
||||
# Set up the web server
|
||||
WEB_SERVER.setup()
|
||||
|
||||
logging.info("Startup complete.")
|
||||
|
||||
# Run the web server. This is the blocking call that keeps the application running in the main thread, so this must
|
||||
# be the last thing we do. web_server.stop() triggers an await condition in the web server which finishes the main
|
||||
# thread.
|
||||
web_server.start()
|
||||
WEB_SERVER.start()
|
||||
|
||||
Reference in New Issue
Block a user