mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Refactor of caching & data storage part 6 #118
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import pytz
|
||||
|
||||
from staticdataproviders.static_data_provider import StaticDataProvider
|
||||
|
||||
|
||||
class LocalFileStaticDataProvider(StaticDataProvider):
|
||||
"""Generic static reference data provider class for providers that fetch their data from a local file on startup."""
|
||||
|
||||
def __init__(self, name, provider_config, path):
|
||||
super().__init__(name, provider_config)
|
||||
self._path = path
|
||||
|
||||
def start(self):
|
||||
logging.debug("Loading " + self.name + " static reference data from file.")
|
||||
try:
|
||||
ok = self._load_data(self._path)
|
||||
if ok:
|
||||
self.status = "OK"
|
||||
self.last_update_time = datetime.now(pytz.UTC)
|
||||
else:
|
||||
self.status = "Error"
|
||||
logging.info("Failed to load data for " + self.name)
|
||||
except Exception as e:
|
||||
self.status = "Error"
|
||||
logging.error("Exception in local file Static Data Provider (" + self.name + ")", e, exc_info=True)
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def _load_data(self, path):
|
||||
"""Load data from the given file path. Return true if successful, false otherwise."""
|
||||
|
||||
raise NotImplementedError("Subclasses must implement this method")
|
||||
Reference in New Issue
Block a user