User new Pyramid settings to start converter process
authorThierry Florac <tflorac@ulthar.net>
Sun, 14 Jan 2018 14:40:16 +0100
changeset 66 6f502c50ef09
parent 65 d38220c1116e
child 67 31fd84f7cc47
User new Pyramid settings to start converter process
src/pyams_media/include.py
src/pyams_media/interfaces/__init__.py
--- a/src/pyams_media/include.py	Thu Jan 11 17:14:45 2018 +0100
+++ b/src/pyams_media/include.py	Sun Jan 14 14:40:16 2018 +0100
@@ -21,7 +21,7 @@
 import sys
 
 # import interfaces
-from pyams_media.interfaces import CONVERTER_HANDLER_KEY, CONVERTER_NAME
+from pyams_media.interfaces import CONVERTER_HANDLER_KEY, CONVERTER_STARTER_KEY, CONVERTER_NAME
 from pyams_utils.interfaces import PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME
 from pyramid.interfaces import IApplicationCreated
 
@@ -31,6 +31,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
 
 
@@ -59,7 +60,7 @@
 
     registry = getGlobalSiteManager()
     settings = registry.settings
-    start_handler = settings.get(CONVERTER_HANDLER_KEY, False)
+    start_handler = asbool(settings.get(CONVERTER_STARTER_KEY, False))
     if start_handler:
         # get database connection
         connection = get_connection_from_settings(settings)
@@ -75,13 +76,13 @@
                 conversion_util = sm.get(CONVERTER_NAME)
                 if conversion_util is not None:
                     # create medias converter process
-                    process = MediaConversionProcess(start_handler, MediaConversionMessageHandler, registry)
-                    logger.debug('Starting medias conversion process {0!r}...'.format(process))
+                    process = MediaConversionProcess(settings.get(CONVERTER_HANDLER_KEY, '127.0.0.1:5556'),
+                                                     MediaConversionMessageHandler, registry)
+                    logger.info('Starting medias converter {0!r}...'.format(process))
                     process.start()
                     if process.is_alive():
                         atexit.register(process_exit_func, process=process)
-                        logger.debug('Started medias conversion process {0!r} with PID {1}...'.format(process,
-                                                                                                      process.pid))
+                        logger.info('Started medias converter with PID {0}.'.format(process.pid))
             finally:
                 if process and not process.is_alive():
                     process.terminate()
--- a/src/pyams_media/interfaces/__init__.py	Thu Jan 11 17:14:45 2018 +0100
+++ b/src/pyams_media/interfaces/__init__.py	Sun Jan 14 14:40:16 2018 +0100
@@ -31,6 +31,7 @@
 #
 
 CONVERTER_NAME = 'Medias converter'
+CONVERTER_STARTER_KEY = 'pyams_media.start_handler'
 CONVERTER_HANDLER_KEY = 'pyams_media.tcp_handler'
 
 CUSTOM_AUDIO_TYPES = (b'application/ogg',)