Check upgrade mode on application startup before starting scheduler process
authorThierry Florac <thierry.florac@onf.fr>
Thu, 27 Aug 2015 11:39:10 +0200
changeset 17 643ce60ce5f7
parent 16 0a23439ac705
child 18 4806161ea41a
Check upgrade mode on application startup before starting scheduler process
src/pyams_scheduler/include.py
--- a/src/pyams_scheduler/include.py	Thu Jul 23 17:28:38 2015 +0200
+++ b/src/pyams_scheduler/include.py	Thu Aug 27 11:39:10 2015 +0200
@@ -18,6 +18,8 @@
 import logging
 logger = logging.getLogger('PyAMS (scheduler')
 
+import sys
+
 # import interfaces
 from pyams_scheduler.interfaces import SCHEDULER_HANDLER_KEY, SCHEDULER_NAME
 from pyams_utils.interfaces import PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME
@@ -29,7 +31,6 @@
 from pyams_utils.registry import set_local_registry, query_utility
 from pyams_utils.zodb import get_connection_from_settings
 from pyams_zmq.process import process_exit_func
-from zmq.error import ZMQError
 
 
 def include_package(config):
@@ -46,16 +47,18 @@
     else:
         config.scan()
 
-    start_handler = config.registry.settings.get(SCHEDULER_HANDLER_KEY, False)
+    # Check for upgrade mode
+    if sys.argv[0].endswith('pyams_upgrade'):
+        return
+
+    settings = config.registry.settings
+    start_handler = settings.get(SCHEDULER_HANDLER_KEY, False)
     if start_handler:
-        # create scheduler process
-        process = SchedulerProcess(start_handler, SchedulerMessageHandler, config.registry)
         # get database connection
-        connection = get_connection_from_settings(config.registry.settings)
+        connection = get_connection_from_settings(settings)
         root = connection.root()
         # get application
-        application_name = config.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
-                                                        PYAMS_APPLICATION_DEFAULT_NAME)
+        application_name = settings.get(PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME)
         application = root.get(application_name)
         if application is not None:
             sm = application.getSiteManager()
@@ -69,6 +72,8 @@
                 else:
                     zeo_connection = query_utility(IZEOConnection, name=zeo_connection_name)
                     if zeo_connection is not None:
+                        # create scheduler process
+                        process = SchedulerProcess(start_handler, SchedulerMessageHandler, config.registry)
                         # load tasks
                         for task in scheduler_util.values():
                             trigger = task.get_trigger(config.registry)
@@ -78,8 +83,8 @@
                                                       name=task.name,
                                                       kwargs={'zeo_settings': zeo_connection.get_settings(),
                                                               'registry': config.registry})
-                        logger.debug("Starting tasks scheduler {0!r}".format(process))
                         # start process
+                        logger.debug("Starting tasks scheduler {0!r}...".format(process))
                         process.start()
                         if process.is_alive():
                             atexit.register(process_exit_func, process=process)