Some core task design changes and renamed the monitor identifier.

This commit is contained in:
Johannes Findeisen 2023-02-21 03:15:34 +01:00
commit 4b57efd734
3 changed files with 10 additions and 8 deletions

View file

@ -18,7 +18,7 @@ from linspector.core.monitors import Monitors
# i currently only increase the 3rd number because the goal is that 0.19.* will become the first # i currently only increase the 3rd number because the goal is that 0.19.* will become the first
# stable version. # stable version.
__version__ = '0.19.63.dev1' __version__ = '0.19.64.dev1'
__author__ = 'Johannes Findeisen <you@hanez.org>' __author__ = 'Johannes Findeisen <you@hanez.org>'

View file

@ -46,7 +46,7 @@ class Monitors:
if kwargs: if kwargs:
log.debug(identifier + ' args ' + str(kwargs)) log.debug(identifier + ' args ' + str(kwargs))
identifier = monitor_group + '_' + os.path.splitext(os.path.basename( identifier = monitor_group + '.' + os.path.splitext(os.path.basename(
monitor_file))[0] monitor_file))[0]
# create Monitor() object and copy monitor_configuration for each instance because # create Monitor() object and copy monitor_configuration for each instance because

View file

@ -63,17 +63,19 @@ class Task:
# i believe the singleton pattern is not required here because all tasks are stored as singleton in # i believe the singleton pattern is not required here because all tasks are stored as singleton in
# a dict already, and they can be executed directly in the equivalent monitor. need to discover this # a dict already, and they can be executed directly in the equivalent monitor. need to discover this
# when tasks are being implemented. # when tasks are being implemented. this is from the old version of Linspector...
# UPDATE: i see that task runners should be executed as separate threads, so maybe they should be
# singleton here to not instantiate more than one instance inside each task. don't know actually...
@Singleton @Singleton
class TaskExecutor: class TaskRunner:
def __init__(self, configuration, environment, log): def __init__(self, configuration, environment, log):
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log self.__log = log
self.queue = Queue() self.queue = Queue()
self.taskInfos = [] self.task_infos = []
task_thread = Thread(target=self._run_worker_thread) task_thread = Thread(target=self._run_worker_thread)
self._instantEnd = False self._instant_end = False
self._running = True self._running = True
task_thread.daemon = True task_thread.daemon = True
task_thread.start() task_thread.start()
@ -92,7 +94,7 @@ class TaskExecutor:
self.__log.error('error ' + str(err)) self.__log.error('error ' + str(err))
def is_instant_end(self): def is_instant_end(self):
return self._instantEnd return self._instant_end
def is_running(self): def is_running(self):
return self._running return self._running
@ -102,7 +104,7 @@ class TaskExecutor:
def stop_immediately(self): def stop_immediately(self):
self._running = False self._running = False
self._instantEnd = True self._instant_end = True
def schedule_task(self, msg, task): def schedule_task(self, msg, task):
self.queue.put((msg, task)) self.queue.put((msg, task))