Commit a1a97d34 authored by David Trattnig's avatar David Trattnig
Browse files

Fixed timer init and cmd chaining. #72

parent 113b3ff0
...@@ -186,6 +186,7 @@ class EngineExecutor(Timer): ...@@ -186,6 +186,7 @@ class EngineExecutor(Timer):
""" """
_lock = None _lock = None
logger = logging.getLogger("AuraEngine") logger = logging.getLogger("AuraEngine")
initialized = None
timer_store = {} timer_store = {}
parent_timer = None parent_timer = None
child_timer = None child_timer = None
...@@ -208,6 +209,7 @@ class EngineExecutor(Timer): ...@@ -208,6 +209,7 @@ class EngineExecutor(Timer):
func (function): The function to be called func (function): The function to be called
param (object): Parameter passt to the function param (object): Parameter passt to the function
""" """
self.initialized = False
self._lock = Lock() self._lock = Lock()
from src.engine import Engine from src.engine import Engine
now_unix = Engine.engine_time() now_unix = Engine.engine_time()
...@@ -252,6 +254,11 @@ class EngineExecutor(Timer): ...@@ -252,6 +254,11 @@ class EngineExecutor(Timer):
""" """
Calls the passed function `func` when the timer is ready. Calls the passed function `func` when the timer is ready.
""" """
while self.initialized == False:
timer.sleep(0.001)
self.logger.info(SU.orange("Waiting until the EngineExecutor is done with initialization..."))
if not self.direct_exec: #TODO Evaluate if we should join for direct exec too
self.join() self.join()
func() func()
...@@ -276,6 +283,7 @@ class EngineExecutor(Timer): ...@@ -276,6 +283,7 @@ class EngineExecutor(Timer):
self.wait_for_parent() self.wait_for_parent()
thread = Thread(name=self.timer_id, target=self.func, args=(self.param,)) thread = Thread(name=self.timer_id, target=self.func, args=(self.param,))
thread.start() thread.start()
self.initialized = True
def exec_timed(self): def exec_timed(self):
...@@ -290,6 +298,7 @@ class EngineExecutor(Timer): ...@@ -290,6 +298,7 @@ class EngineExecutor(Timer):
else: self.func() else: self.func()
super().__init__(self.diff, wrapper_func, (self.param,)) super().__init__(self.diff, wrapper_func, (self.param,))
self._name = self.timer_id self._name = self.timer_id
self.initialized = True
def update_store(self): def update_store(self):
......
...@@ -296,7 +296,7 @@ class AuraScheduler(threading.Thread): ...@@ -296,7 +296,7 @@ class AuraScheduler(threading.Thread):
Since each scheduled playlist can consist of multiple entry types such as *file*, *live*, Since each scheduled playlist can consist of multiple entry types such as *file*, *live*,
and *stream*, the play-out of the timeslot is actually a bit more complex. Before any playlist and *stream*, the play-out of the timeslot is actually a bit more complex. Before any playlist
entries of the timeslot can be turned into sound, they need to be grouped, queued and pre-loaded. entries of the timeslot can be turned into sound, they need to be aggregated, queued and pre-loaded.
1. First, all entries are aggregated when they hold filesystem entries. 1. First, all entries are aggregated when they hold filesystem entries.
Given you have a playlist with 10 entries, the first 4 are consisting of files, the next two Given you have a playlist with 10 entries, the first 4 are consisting of files, the next two
...@@ -424,8 +424,9 @@ class TimeslotCommand(EngineExecutor): ...@@ -424,8 +424,9 @@ class TimeslotCommand(EngineExecutor):
fade_out_time = float(self.config.get("fade_out_time")) fade_out_time = float(self.config.get("fade_out_time"))
start_fade_out = timeslot.end_unix - fade_out_time start_fade_out = timeslot.end_unix - fade_out_time
self.logger.info(f"Fading out timeslot in {start_fade_out} seconds at {timeslot.timeslot_end} | Timeslot: {timeslot}") self.logger.info(f"Fading out timeslot in {start_fade_out} seconds at {timeslot.timeslot_end} | Timeslot: {timeslot}")
# Initialize the "fade in" EngineExecuter and instatiate a connected child EngineExecuter for "fade out" when the parent is ready
super().__init__("TIMESLOT", None, timeslot.start_unix, self.do_start_timeslot, timeslot) super().__init__("TIMESLOT", None, timeslot.start_unix, self.do_start_timeslot, timeslot)
EngineExecutor("TIMESLOT", self, start_fade_out, self.do_end_timeslot, timeslot) self.on_ready(lambda: EngineExecutor("TIMESLOT", self, start_fade_out, self.do_end_timeslot, timeslot))
def do_start_timeslot(self, timeslot): def do_start_timeslot(self, timeslot):
...@@ -453,7 +454,7 @@ class TimeslotCommand(EngineExecutor): ...@@ -453,7 +454,7 @@ class TimeslotCommand(EngineExecutor):
class PlayCommand(EngineExecutor): class PlayCommand(EngineExecutor):
""" """
Command for triggering start and end of timeslot events. Command for triggering timed preloading and playing as a child command.
""" """
engine = None engine = None
config = None config = None
...@@ -471,7 +472,8 @@ class PlayCommand(EngineExecutor): ...@@ -471,7 +472,8 @@ class PlayCommand(EngineExecutor):
start_preload = entries[0].start_unix - self.config.get("preload_offset") start_preload = entries[0].start_unix - self.config.get("preload_offset")
start_play = entries[0].start_unix start_play = entries[0].start_unix
preload_timer = super().__init__("PLAY", None, start_preload, self.do_preload, entries) # Initialize the "preload" EngineExecuter and attach a child `PlayCommand` to the "on_ready" event handler
preload_timer = super().__init__("PRELOAD", None, start_preload, self.do_preload, entries)
self.on_ready(lambda: EngineExecutor("PLAY", self, start_play, self.do_play, entries)) self.on_ready(lambda: EngineExecutor("PLAY", self, start_play, self.do_play, entries))
...@@ -509,5 +511,3 @@ class PlayCommand(EngineExecutor): ...@@ -509,5 +511,3 @@ class PlayCommand(EngineExecutor):
self.logger.info(self.engine.scheduler.timeslot_renderer.get_ascii_timeslots()) self.logger.info(self.engine.scheduler.timeslot_renderer.get_ascii_timeslots())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment