diff --git a/src/scheduling/programme.py b/src/scheduling/programme.py index 6adcce9776dc5856473596ea0a6de948392c501c..0104de7ef32b3d6a71a1c49782cd908135128fd4 100644 --- a/src/scheduling/programme.py +++ b/src/scheduling/programme.py @@ -184,25 +184,7 @@ class ProgrammeService(): else: break - return self.filter_scheduling_window(next_timeslots) - - - - def filter_scheduling_window(self, timeslots): - """ - Ignore timeslots which are beyond the scheduling window. The end of the scheduling window - is defined by the config option `scheduling_window_end`. This value defines the seconds - minus the actual start time of the timeslot. - """ - now_unix = Engine.engine_time() - len_before = len(timeslots) - window_start = self.config.get("scheduling_window_start") - window_end = self.config.get("scheduling_window_end") - timeslots = list(filter(lambda s: (s.start_unix - window_end) > now_unix and (s.start_unix - window_start) < now_unix, timeslots)) - len_after = len(timeslots) - self.logger.info("For now, skipped %s future timeslot(s) which are out of the scheduling window (T-%ss to T-%ss)" % ((len_before - len_after), window_start, window_end)) - - return timeslots + return next_timeslots diff --git a/src/scheduling/scheduler.py b/src/scheduling/scheduler.py index 354c5c1b37b6af7eb8af1c0f01fa37419f834e64..c50b888c98838ed48ff4bcadb4f128c7b27f5764 100644 --- a/src/scheduling/scheduler.py +++ b/src/scheduling/scheduler.py @@ -35,7 +35,7 @@ from src.core.resources import ResourceClass, ResourceUtil from src.scheduling.utils import TimeslotRenderer from src.scheduling.programme import ProgrammeService - +from src.scheduling.models import Playlist class AuraScheduler(threading.Thread): @@ -45,16 +45,6 @@ class AuraScheduler(threading.Thread): - Retrieves data from Steering and Tank - Executes engine actions in an automated fashion - Attributes: - config (AuraConfig): Holds the Engine Configuration - logger: The logger - exit_event(threading.Event): Used to exit the thread if requested - engine: Virtual mixer - last_successful_fetch (datetime): Stores the last time a fetch from Steering/Tank was successful - - programme: The current radio programme to be played as defined in the local engine database - active_entry(Show, Track): This is a Tuple consisting of the currently played `Show` and `Track` - message_timer(List<threading.Timer>): The timer queue of sound-system commands for playlists/entries to be played """ config = None logger = None @@ -163,9 +153,10 @@ class AuraScheduler(threading.Thread): if entry.channel in ChannelType.FALLBACK_QUEUE.channels: return - if entry.playlist and entry.playlist.timeslot: - timeslot = entry.playlist.timeslot - timeslot.set_active_entry(entry) + current_timeslot = self.programme.get_current_timeslot() + if current_timeslot: + current_timeslot.set_active_entry(entry) + # @@ -262,6 +253,7 @@ class AuraScheduler(threading.Thread): # Get a clean set of the timeslots within the scheduling window timeslots = self.programme.get_next_timeslots() + timeslots = self.filter_scheduling_window(timeslots) # Queue the timeslots, their playlists and entries if timeslots: @@ -363,6 +355,26 @@ class AuraScheduler(threading.Thread): + def filter_scheduling_window(self, timeslots): + """ + Ignore timeslots which are beyond the scheduling window. The end of the scheduling window + is defined by the config option `scheduling_window_end`. This value defines the seconds + minus the actual start time of the timeslot. + """ + if not timeslots: + return timeslots + + now_unix = Engine.engine_time() + len_before = len(timeslots) + window_start = self.config.get("scheduling_window_start") + window_end = self.config.get("scheduling_window_end") + timeslots = list(filter(lambda s: (s.start_unix - window_end) > now_unix and (s.start_unix - window_start) < now_unix, timeslots)) + len_after = len(timeslots) + self.logger.info("For now, skipped %s future timeslot(s) which are out of the scheduling window (T-%ss to T-%ss)" % ((len_before - len_after), window_start, window_end)) + + return timeslots + + def terminate(self): """