Commit e737a7bb authored by Alain Takoudjou's avatar Alain Takoudjou

monitor: promise timemout is now configurable. Default value is 20

parent d1d7044f
......@@ -94,6 +94,8 @@ class Monitoring(object):
self.pid_file = config.get("monitor", "pid-file")
self.monitor_promise_folder = softConfigGet(config, "monitor",
"monitor-promise-folder")
self.promise_timeout_file = softConfigGet(config, "monitor",
"promises-timeout-file")
self.config_folder = os.path.join(self.private_folder, 'config')
self.report_folder = self.private_folder
......@@ -101,6 +103,7 @@ class Monitoring(object):
self.promise_output_file = config.get("monitor", "promise-output-file")
self.bootstrap_is_ok = True
def loadConfig(self, pathes, config=None):
if config is None:
config = ConfigParser.ConfigParser()
......@@ -411,6 +414,7 @@ class Monitoring(object):
"monitor-promises.pid"),
'--output "%s"' % self.public_folder,
'--promise_folder "%s"' % self.promise_folder,
'--timeout_file "%s"' % self.promise_timeout_file,
'--monitor_promise_folder "%s"' % self.monitor_promise_folder,
'--monitor_url "%s/jio_private/"' % self.webdav_url, # XXX hardcoded,
'--history_folder "%s"' % self.public_folder,
......
......@@ -12,8 +12,8 @@ import glob
import argparse
import traceback
# Promise timeout after 12 seconds
promise_timeout = 12
# Promise timeout after 20 seconds by default
promise_timeout = 20
def parseArguments():
"""
......@@ -32,6 +32,9 @@ def parseArguments():
help='Folder where to find Custom monitor promises to execute.')
parser.add_argument('--promise_name',
help='Title to give to this promise.')
parser.add_argument('--timeout_file',
default='',
help='File containing Max timeout for each promise run.')
parser.add_argument('--promise_type',
default='status',
help='Type of promise to execute. [status, report].')
......@@ -52,6 +55,15 @@ class RunPromise(object):
def __init__(self, config_parser):
self.config = config_parser
self.promise_timeout = promise_timeout
if self.config.timeout_file and \
os.path.exists(self.config.timeout_file):
with open(self.config.timeout_file) as tf:
timeout = tf.read()
if timeout.isdigit():
self.promise_timeout = int(timeout)
else:
print "%s it not a valid promise-timeout value" % timeout
def runpromise(self):
......@@ -298,7 +310,7 @@ class RunPromise(object):
process_handler.stdin = None
sleep_time = 0.1
increment_limit = int(promise_timeout / sleep_time)
increment_limit = int(self.promise_timeout / sleep_time)
for current_increment in range(0, increment_limit):
if process_handler.poll() is None:
time.sleep(sleep_time)
......@@ -318,7 +330,7 @@ class RunPromise(object):
message = process_handler.stderr.read()
if message is None:
message = process_handler.stdout.read() or ""
message += '\nPROMISE TIME OUT AFTER %s SECONDS' % promise_timeout
message += '\nPROMISE TIME OUT AFTER %s SECONDS' % self.promise_timeout
result_dict["message"] = message
promise_result_list.append(result_dict)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment