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

Proper handling for aborted timers. #78

parent 847c7ca1
No related branches found
No related tags found
No related merge requests found
Pipeline #1031 failed
# #
# Aura Engine (https://gitlab.servus.at/aura/engine) # Aura Engine (https://gitlab.servus.at/aura/engine)
# #
# Copyright (C) 2017-2020 - The Aura Engine Team. # Copyright (C) 2017-now() - The Aura Engine Team.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -186,15 +186,15 @@ class EngineExecutor(Timer): ...@@ -186,15 +186,15 @@ class EngineExecutor(Timer):
""" """
timer_store: dict = {} timer_store: dict = {}
logger = logging.getLogger("AuraEngine") logger = logging.getLogger("AuraEngine")
EVENT_ON_READY = "on_ready"
_lock = None _lock = None
direct_exec: bool = None direct_exec: bool = None
is_aborted: bool = None
parent_timer: Timer = None parent_timer: Timer = None
child_timer: Timer = None child_timer: Timer = None
timer_id: str = None timer_id: str = None
timer_type: str = None timer_type: str = None
func = None func: func = None
param = None param = None
diff = None diff = None
dt = None dt = None
...@@ -222,6 +222,7 @@ class EngineExecutor(Timer): ...@@ -222,6 +222,7 @@ class EngineExecutor(Timer):
# Init meta data # Init meta data
self.direct_exec = False self.direct_exec = False
self.is_aborted = False
self.timer_type = timer_type self.timer_type = timer_type
self.timer_id = f"{timer_type}:{func.__name__}:{due_time}" self.timer_id = f"{timer_type}:{func.__name__}:{due_time}"
...@@ -236,11 +237,12 @@ class EngineExecutor(Timer): ...@@ -236,11 +237,12 @@ class EngineExecutor(Timer):
is_stored = self.update_store() is_stored = self.update_store()
if not is_stored: if not is_stored:
self.logger.info(SU.red(f"Timer '{self.timer_id}' omitted because it's already existing but dead")) self.logger.info(SU.yellow(f"Timer '{self.timer_id}' omitted because it's already existing but dead"))
self.is_aborted = True
else: else:
if diff < 0: if diff < 0:
msg = f"Timer '{self.timer_id}' is due in the past. Executing immediately ..." msg = f"Timer '{self.timer_id}' is due in the past. Executing immediately ..."
self.logger.warn(SU.yellow(msg)) self.logger.warning(SU.yellow(msg))
self.exec_now() self.exec_now()
elif diff == 0: elif diff == 0:
self.logger.debug(f"Timer '{self.timer_id}' to be executed immediately") self.logger.debug(f"Timer '{self.timer_id}' to be executed immediately")
...@@ -274,7 +276,6 @@ class EngineExecutor(Timer): ...@@ -274,7 +276,6 @@ class EngineExecutor(Timer):
self.direct_exec = True self.direct_exec = True
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,))
time.sleep(0.2)
thread.start() thread.start()
...@@ -293,7 +294,6 @@ class EngineExecutor(Timer): ...@@ -293,7 +294,6 @@ 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
time.sleep(0.2)
self.start() self.start()
...@@ -342,6 +342,8 @@ class EngineExecutor(Timer): ...@@ -342,6 +342,8 @@ class EngineExecutor(Timer):
""" """
if self.direct_exec == True: if self.direct_exec == True:
return False return False
if self.is_aborted == True:
return False
return super().is_alive() return super().is_alive()
...@@ -370,6 +372,14 @@ class EngineExecutor(Timer): ...@@ -370,6 +372,14 @@ class EngineExecutor(Timer):
del EngineExecutor.timer_store[timer_id] del EngineExecutor.timer_store[timer_id]
@staticmethod
def command_history():
"""
Returns a list of recent active and inactive timers to the logger.
"""
return EngineExecutor.timer_store.values()
@staticmethod @staticmethod
def log_commands(): def log_commands():
""" """
......
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