made task threads a daemon; moved TaskList to task.py
This commit is contained in:
parent
bbd078d706
commit
b3a89b98a3
2 changed files with 40 additions and 12 deletions
|
|
@ -32,7 +32,7 @@ from periods import CronPeriod, DatePeriod, IntervalPeriod
|
|||
from linspector.services.service import Service
|
||||
from linspector.processors.processor import Processor
|
||||
from linspector.parsers.parser import Parser
|
||||
from linspector.tasks.TaskList import TaskList
|
||||
from linspector.tasks.task import TaskList
|
||||
|
||||
MOD_SERVICES = "services"
|
||||
MOD_PROCESSORS = "processors"
|
||||
|
|
@ -218,9 +218,6 @@ def parsePeriodList(name, values):
|
|||
|
||||
|
||||
class FullConfigParser(ConfigParser):
|
||||
|
||||
|
||||
|
||||
def parse_config(self, configFilename):
|
||||
"""
|
||||
parses the json configuration and returns a list of layouts,
|
||||
|
|
@ -264,10 +261,6 @@ class FullConfigParser(ConfigParser):
|
|||
class_check = lambda processor: isinstance(processor, Processor)
|
||||
self.replace_with_import(self.hostgroups, MOD_PROCESSORS, items_func, class_check)
|
||||
|
||||
#items_func = lambda member: member.get_tasks()
|
||||
#class_check = lambda task: isinstance(task, Task)
|
||||
#self.replace_with_import(members, MOD_TASKS, items_func, class_check)
|
||||
|
||||
services = []
|
||||
for hg in self.hostgroups:
|
||||
services.extend(hg.get_services())
|
||||
|
|
@ -296,7 +289,6 @@ class FullConfigParser(ConfigParser):
|
|||
linConf.set_periods(periods)
|
||||
linConf.set_task_list(taskList)
|
||||
|
||||
|
||||
for hg in self.hostgroups:
|
||||
for service in hg.get_services():
|
||||
service.set_hostgroup(hg)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
The task class.
|
||||
The task classes.
|
||||
|
||||
Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg"
|
||||
Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg
|
||||
|
||||
This file is part of Linspector (http://linspector.org).
|
||||
|
||||
|
|
@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from threading import Event, Thread
|
||||
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
|
@ -36,4 +38,38 @@ class Task:
|
|||
return self._taskType
|
||||
|
||||
def execute(self, msg, args):
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
class TaskList(object):
|
||||
def __init__(self, tasks):
|
||||
self.tasks = tasks
|
||||
self.event = Event()
|
||||
self.taskInfos = []
|
||||
task_thread = Thread(target=self._run_worker_thread)
|
||||
task_thread.setDaemon(True)
|
||||
task_thread.start()
|
||||
|
||||
def _run_worker_thread(self):
|
||||
while True:
|
||||
if len(self.taskInfos) == 0:
|
||||
self.event.clear()
|
||||
self.event.wait()
|
||||
msg, taskInfos = self.taskInfos[0]
|
||||
del self.taskInfos[0]
|
||||
try:
|
||||
for taskInfo in taskInfos:
|
||||
task = self.find_task_by_name(taskInfo["class"])
|
||||
if task:
|
||||
task.execute(msg, taskInfo["args"])
|
||||
except:
|
||||
pass
|
||||
|
||||
def find_task_by_name(self, clazzName):
|
||||
for task in self.tasks:
|
||||
if task.get_task_type() == clazzName:
|
||||
return task
|
||||
|
||||
def execute_task_infos(self, msg, taskInfos):
|
||||
self.taskInfos.append((msg, taskInfos))
|
||||
self.event.set()
|
||||
Loading…
Add table
Add a link
Reference in a new issue