From 5bbf0e08b6689b144d394a594a664be189c7dc49 Mon Sep 17 00:00:00 2001 From: Danis Valiullin Date: Fri, 4 May 2018 17:27:55 +0300 Subject: [PATCH] Fixes #58 Added reading of conf files if exists --- src/webhook_launcher/app/boss.py | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/webhook_launcher/app/boss.py b/src/webhook_launcher/app/boss.py index 9549a9c..aeb6bc7 100644 --- a/src/webhook_launcher/app/boss.py +++ b/src/webhook_launcher/app/boss.py @@ -16,9 +16,34 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import json +import os + from django.conf import settings from RuoteAMQP import Launcher + +def get_process_params(pdef_file_path): + """Read process configuration variables if exists + :param pdef_file_path: process file path, + config file should be with the same name and with '.conf' extension + :return Loaded variables or None if couldn't read the conf file + """ + params = None + if os.path.exists(pdef_file_path): + file_name, _file_ext = os.path.splitext(pdef_file_path) + conf_file_path = file_name + '.conf' + try: + params = json.load(open(conf_file_path)) + except OSError: + pass + + except ValueError as e: + print 'Error while loading json %s:\n%s' % (conf_file_path, str(e)) + + return params + + def launch(process, fields): """ BOSS process launcher @@ -33,8 +58,12 @@ def launch(process, fields): amqp_pass = settings.BOSS_PASS, amqp_vhost = settings.BOSS_VHOST) - print "launching to (%s,%s)" %(settings.BOSS_HOST, settings.BOSS_VHOST) - launcher.launch(pdef, fields) + fields_dict = get_process_params(process) or {} + fields_dict.update(fields) + + print "launching to (%s,%s)" % (settings.BOSS_HOST, settings.BOSS_VHOST) + launcher.launch(pdef, fields_dict) + def launch_queue(fields): launch(settings.VCSCOMMIT_QUEUE, fields)