mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import logging
|
|
from datetime import datetime
|
|
|
|
import pytz
|
|
|
|
from core.data_store import DATA_STORE
|
|
|
|
|
|
class SIGRefDataProvider:
|
|
"""Generic SIG reference data provider class. Subclasses of this query the individual URLs or files for data."""
|
|
|
|
def __init__(self, sig_name, provider_config):
|
|
"""Constructor"""
|
|
|
|
self.sig_name = sig_name
|
|
self.enabled = provider_config["enabled"]
|
|
self.last_update_time = datetime.min.replace(tzinfo=pytz.UTC)
|
|
self.status = "Not Started" if self.enabled else "Disabled"
|
|
self.reference_count = 0
|
|
|
|
|
|
def start(self):
|
|
"""Start the provider. This should return immediately after spawning threads to access the remote resources"""
|
|
|
|
raise NotImplementedError("Subclasses must implement this method")
|
|
|
|
|
|
def stop(self):
|
|
"""Stop any threads and prepare for application shutdown"""
|
|
|
|
raise NotImplementedError("Subclasses must implement this method")
|
|
|
|
def _add_data(self, new_data):
|
|
"""Add all the provided reference data objects to the data store."""
|
|
|
|
for d in new_data:
|
|
DATA_STORE.sigrefs[self.sig_name + ":" + d.id] = d
|
|
self.reference_count = len(new_data)
|
|
logging.info(f"Loaded %d references for %s into the data store.", self.reference_count, self.sig_name)
|