Commit 6945acb4 authored by david's avatar david
Browse files

Proper handling for aborted timers. #78

parent 847c7ca1
Pipeline #1031 failed with stage
#
# 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
# it under the terms of the GNU Affero General Public License as published by
......@@ -186,15 +186,15 @@ class EngineExecutor(Timer):
"""
timer_store: dict = {}
logger = logging.getLogger("AuraEngine")
EVENT_ON_READY = "on_ready"
_lock = None
direct_exec: bool = None
is_aborted: bool = None
parent_timer: Timer = None
child_timer: Timer = None
timer_id: str = None
timer_type: str = None
func = None
func: func = None
param = None
diff = None
dt = None
......@@ -222,6 +222,7 @@ class EngineExecutor(Timer):
# Init meta data
self.direct_exec = False
self.is_aborted = False
self.timer_type = timer_type
self.timer_id = f"{timer_type}:{func.__name__}:{due_time}"
......@@ -236,11 +237,12 @@ class EngineExecutor(Timer):
is_stored = self.update_store()
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:
if diff < 0:
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()
elif diff == 0:
self.logger.debug(f"Timer '{self.timer_id}' to be executed immediately")
......@@ -274,7 +276,6 @@ class EngineExecutor(Timer):
self.direct_exec = True
self.wait_for_parent()
thread = Thread(name=self.timer_id, target=self.func, args=(self.param,))
time.sleep(0.2)
thread.start()
......@@ -293,7 +294,6 @@ class EngineExecutor(Timer):
else: self.func()
super().__init__(self.diff, wrapper_func, (self.param,))
self._name = self.timer_id
time.sleep(0.2)
self.start()
......@@ -342,6 +342,8 @@ class EngineExecutor(Timer):
"""
if self.direct_exec == True:
return False
if self.is_aborted == True:
return False
return super().is_alive()
......@@ -370,6 +372,14 @@ class EngineExecutor(Timer):
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
def log_commands():
"""
......
Markdown is supported
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