# HG changeset patch # User Thierry Florac # Date 1515937764 -3600 # Node ID aa374e033e84ea0c86b7eca583a187b14a2a24af # Parent 8cacad2470d5f0605eb2f72d999acb9a837b1471 Use Pyramid settings to start scheduler process diff -r 8cacad2470d5 -r aa374e033e84 src/pyams_scheduler/include.py --- a/src/pyams_scheduler/include.py Sun Jan 14 14:48:58 2018 +0100 +++ b/src/pyams_scheduler/include.py Sun Jan 14 14:49:24 2018 +0100 @@ -21,7 +21,7 @@ import sys # import interfaces -from pyams_scheduler.interfaces import SCHEDULER_HANDLER_KEY, SCHEDULER_NAME +from pyams_scheduler.interfaces import SCHEDULER_HANDLER_KEY, SCHEDULER_STARTER_KEY, SCHEDULER_NAME from pyams_utils.interfaces import PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME from pyramid.interfaces import IApplicationCreated from zope.interface.interfaces import ComponentLookupError @@ -32,6 +32,7 @@ from pyams_utils.zodb import get_connection_from_settings from pyams_zmq.process import process_exit_func from pyramid.events import subscriber +from pyramid.settings import asbool from zope.component.globalregistry import getGlobalSiteManager @@ -60,7 +61,7 @@ registry = getGlobalSiteManager() settings = registry.settings - start_handler = settings.get(SCHEDULER_HANDLER_KEY, False) + start_handler = asbool(settings.get(SCHEDULER_STARTER_KEY, False)) if start_handler: # get database connection connection = get_connection_from_settings(settings) @@ -80,7 +81,8 @@ pass else: # create scheduler process - process = SchedulerProcess(start_handler, SchedulerMessageHandler, registry) + process = SchedulerProcess(settings.get(SCHEDULER_HANDLER_KEY, '127.0.0.1:5555'), + SchedulerMessageHandler, registry) # load tasks for task in scheduler_util.values(): trigger = task.get_trigger(registry) @@ -91,11 +93,11 @@ kwargs={'zodb_name': zodb_name, 'registry': registry}) # start process - logger.debug("Starting tasks scheduler {0!r}...".format(process)) + logger.info("Starting tasks scheduler {0!r}...".format(process)) process.start() if process.is_alive(): atexit.register(process_exit_func, process=process) - logger.debug("Started tasks scheduler {0!r} with PID {1}...".format(process, process.pid)) + logger.info("Started tasks scheduler with PID {0}.".format(process.pid)) finally: if process and not process.is_alive(): process.terminate() diff -r 8cacad2470d5 -r aa374e033e84 src/pyams_scheduler/interfaces/__init__.py --- a/src/pyams_scheduler/interfaces/__init__.py Sun Jan 14 14:48:58 2018 +0100 +++ b/src/pyams_scheduler/interfaces/__init__.py Sun Jan 14 14:49:24 2018 +0100 @@ -86,6 +86,7 @@ SCHEDULER_NAME = 'Tasks scheduler' +SCHEDULER_STARTER_KEY = 'pyams_scheduler.start_handler' SCHEDULER_HANDLER_KEY = 'pyams_scheduler.tcp_handler' SCHEDULER_JOBSTORE_KEY = 'pyams_scheduler.jobs' diff -r 8cacad2470d5 -r aa374e033e84 src/pyams_scheduler/process.py --- a/src/pyams_scheduler/process.py Sun Jan 14 14:48:58 2018 +0100 +++ b/src/pyams_scheduler/process.py Sun Jan 14 14:49:24 2018 +0100 @@ -169,6 +169,13 @@ class SchedulerHandler(object): """Scheduler handler""" + def test(self, settings): + messages = [ + 'OK - Tasks scheduler ready to handle requests.', + '{0} currently running jobs'.format(len(self.process.scheduler.get_jobs())) + ] + return [200, '\n'.join(messages)] + def get_jobs(self, settings): scheduler = self.process.scheduler return [200,