Skip to content

Commit ff9f811

Browse files
committed
Fixes #58 Added reading of conf files if exists
1 parent 937c944 commit ff9f811

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/webhook_launcher/app/boss.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,34 @@
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818

19+
import json
20+
import os
21+
1922
from django.conf import settings
2023
from RuoteAMQP import Launcher
2124

25+
26+
def get_process_params(pdef_file_path):
27+
"""Read process configuration variables if exists
28+
:param pdef_file_path: process file path,
29+
config file should be with the same name and with '.conf' extension
30+
:return Loaded variables or None if couldn't read the conf file
31+
"""
32+
params = None
33+
if os.path.exists(pdef_file_path):
34+
file_name, _file_ext = os.path.splitext(pdef_file_path)
35+
conf_file_path = file_name + '.conf'
36+
try:
37+
params = json.load(open(conf_file_path))
38+
except OSError:
39+
pass
40+
41+
except ValueError as e:
42+
print 'Error while loading json %s:\n%s' % (conf_file_path, str(e))
43+
44+
return params
45+
46+
2247
def launch(process, fields):
2348
""" BOSS process launcher
2449
@@ -33,9 +58,13 @@ def launch(process, fields):
3358
amqp_pass = settings.BOSS_PASS,
3459
amqp_vhost = settings.BOSS_VHOST)
3560

36-
print "launching to (%s,%s)" %(settings.BOSS_HOST, settings.BOSS_VHOST)
61+
fields_dict = get_process_params(process) or {}
62+
fields_dict.update(fields)
63+
64+
print "launching to (%s,%s)" % (settings.BOSS_HOST, settings.BOSS_VHOST)
3765
launcher.launch(pdef, fields)
3866

67+
3968
def launch_queue(fields):
4069
launch(settings.VCSCOMMIT_QUEUE, fields)
4170

0 commit comments

Comments
 (0)