Added basic scheduler code.
This commit is contained in:
parent
fd7bad223f
commit
ca6b424473
3 changed files with 36 additions and 6 deletions
|
|
@ -7,21 +7,26 @@ import importlib
|
|||
|
||||
from logging import getLogger
|
||||
|
||||
#from apscheduler.schedulers.background import BackgroundScheduler
|
||||
#from apscheduler.jobstores.memory import MemoryJobStore
|
||||
#from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.jobstores.memory import MemoryJobStore
|
||||
from apscheduler.executors.pool import ThreadPoolExecutor # , ProcessPoolExecutor
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def job_function(job):
|
||||
job.handle_call()
|
||||
|
||||
|
||||
class Linspector:
|
||||
|
||||
def __init__(self, configuration, environment, monitors, plugins):
|
||||
def __init__(self, configuration, environment, monitors, plugins, scheduler):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__monitors = monitors
|
||||
self.__plugin_list = None
|
||||
self.__plugins = plugins
|
||||
self.__scheduler = scheduler
|
||||
|
||||
# load plugins
|
||||
logger.info('loading plugins...')
|
||||
|
|
@ -36,6 +41,25 @@ class Linspector:
|
|||
plugin = plugin_module.get(configuration, environment, self)
|
||||
plugins[plugin_option.lower()] = plugin
|
||||
|
||||
jobstores = {
|
||||
'memory': MemoryJobStore()
|
||||
}
|
||||
executors = {
|
||||
'default': ThreadPoolExecutor(int(configuration.get_option('linspector',
|
||||
'max_threads'))),
|
||||
#'default': ProcessPoolExecutor(int(configuration.get_option('linspector',
|
||||
# 'max_processes')))
|
||||
}
|
||||
job_defaults = {
|
||||
'max_instances': 10000
|
||||
}
|
||||
self.__scheduler['linspector'] = BackgroundScheduler(jobstores=jobstores,
|
||||
executors=executors,
|
||||
job_defaults=job_defaults)
|
||||
|
||||
if configuration.get_option('linspector', 'start_scheduler') == 'true':
|
||||
self.__scheduler['linspector'].start()
|
||||
|
||||
# this function is just for testing purposes and can be removed some day
|
||||
def print_debug(self):
|
||||
# example on how to access the monitor objects in monitors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue