Skip to content
Snippets Groups Projects
Commit fe7b6b74 authored by David Trattnig's avatar David Trattnig
Browse files

refactor(tt): pass api fetcher in constructor

parent c4663af5
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
...@@ -243,7 +243,7 @@ class AuraScheduler(threading.Thread): ...@@ -243,7 +243,7 @@ class AuraScheduler(threading.Thread):
""" """
self.config = AuraConfig.config() self.config = AuraConfig.config()
self.logger = logging.getLogger("engine") self.logger = logging.getLogger("engine")
self.timetable = timetable.TimetableService(self.config.get("cache_dir")) self.timetable = timetable.TimetableService(self.config.get("cache_dir"), api.ApiFetcher())
self.timetable_renderer = utils.TimetableRenderer(self) self.timetable_renderer = utils.TimetableRenderer(self)
self.engine = engine self.engine = engine
self.engine.scheduler = self self.engine.scheduler = self
...@@ -285,7 +285,7 @@ class AuraScheduler(threading.Thread): ...@@ -285,7 +285,7 @@ class AuraScheduler(threading.Thread):
self.logger.info(SU.cyan(msg)) self.logger.info(SU.cyan(msg))
# Load some stuff from the API in any case # Load some stuff from the API in any case
self.timetable.refresh(api.ApiFetcher()) self.timetable.refresh()
# Queue only when the engine is ready to play # Queue only when the engine is ready to play
if self.is_initialized: if self.is_initialized:
......
...@@ -56,12 +56,13 @@ class TimetableService: ...@@ -56,12 +56,13 @@ class TimetableService:
cache_location: str = None cache_location: str = None
timetable_file: str = None timetable_file: str = None
def __init__(self, cache_location: str): def __init__(self, cache_location: str, api_fetcher: api.ApiFetcher):
""" """
Initialize. Initialize.
Args: Args:
cache_location (str): Path to folder where timetable.json is cached. cache_location (str): Path to folder where timetable.json is cached.
api_fetcher (ApiFetcher): Service to fetch timeslots and playlists.
""" """
self.config = AuraConfig.config() self.config = AuraConfig.config()
self.logger = logging.getLogger("engine") self.logger = logging.getLogger("engine")
...@@ -73,9 +74,10 @@ class TimetableService: ...@@ -73,9 +74,10 @@ class TimetableService:
os.makedirs(cache_location, exist_ok=True) os.makedirs(cache_location, exist_ok=True)
self.cache_location = cache_location self.cache_location = cache_location
self.timetable_file = self.cache_location + "/timetable.json" self.timetable_file = self.cache_location + "/timetable.json"
self.api_fetcher = api_fetcher
self.load_timetable() self.load_timetable()
def refresh(self, fetcher: api.ApiFetcher): def refresh(self):
""" """
Update the timetable. Update the timetable.
...@@ -83,14 +85,11 @@ class TimetableService: ...@@ -83,14 +85,11 @@ class TimetableService:
2. Merge with the current timetable. 2. Merge with the current timetable.
3. Persist to `timetable.json` 3. Persist to `timetable.json`
Args:
fetcher (ApiFetcher): Service to fetch timeslots and playlists.
""" """
self.logger.debug("Trying to fetch new timeslots from API endpoints...") self.logger.debug("Trying to fetch new timeslots from API endpoints...")
# Create a fetching thread and wait until it is done # Create a fetching thread and wait until it is done
self.api_fetcher = fetcher self.api_fetcher.start()
fetcher.start() response = self.api_fetcher.fetch()
response = fetcher.fetch()
if response.code == 0: if response.code == 0:
if len(response.timeslots) > 0: if len(response.timeslots) > 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment