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

Proper location for scheduling window. #41

parent 96bfc486
No related branches found
No related tags found
No related merge requests found
...@@ -184,25 +184,7 @@ class ProgrammeService(): ...@@ -184,25 +184,7 @@ class ProgrammeService():
else: else:
break break
return self.filter_scheduling_window(next_timeslots) return 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
......
...@@ -35,7 +35,7 @@ from src.core.resources import ResourceClass, ResourceUtil ...@@ -35,7 +35,7 @@ from src.core.resources import ResourceClass, ResourceUtil
from src.scheduling.utils import TimeslotRenderer from src.scheduling.utils import TimeslotRenderer
from src.scheduling.programme import ProgrammeService from src.scheduling.programme import ProgrammeService
from src.scheduling.models import Playlist
class AuraScheduler(threading.Thread): class AuraScheduler(threading.Thread):
...@@ -45,16 +45,6 @@ class AuraScheduler(threading.Thread): ...@@ -45,16 +45,6 @@ class AuraScheduler(threading.Thread):
- Retrieves data from Steering and Tank - Retrieves data from Steering and Tank
- Executes engine actions in an automated fashion - 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 config = None
logger = None logger = None
...@@ -163,9 +153,10 @@ class AuraScheduler(threading.Thread): ...@@ -163,9 +153,10 @@ class AuraScheduler(threading.Thread):
if entry.channel in ChannelType.FALLBACK_QUEUE.channels: if entry.channel in ChannelType.FALLBACK_QUEUE.channels:
return return
if entry.playlist and entry.playlist.timeslot: current_timeslot = self.programme.get_current_timeslot()
timeslot = entry.playlist.timeslot if current_timeslot:
timeslot.set_active_entry(entry) current_timeslot.set_active_entry(entry)
# #
...@@ -262,6 +253,7 @@ class AuraScheduler(threading.Thread): ...@@ -262,6 +253,7 @@ class AuraScheduler(threading.Thread):
# Get a clean set of the timeslots within the scheduling window # Get a clean set of the timeslots within the scheduling window
timeslots = self.programme.get_next_timeslots() timeslots = self.programme.get_next_timeslots()
timeslots = self.filter_scheduling_window(timeslots)
# Queue the timeslots, their playlists and entries # Queue the timeslots, their playlists and entries
if timeslots: if timeslots:
...@@ -363,6 +355,26 @@ class AuraScheduler(threading.Thread): ...@@ -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): def terminate(self):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment