Commit 5698a3fb authored by Nicolas Wavrant's avatar Nicolas Wavrant

notifier.py: new argument allowing to run the executable several times in case of failure

parent cc34cbb2
Pipeline #3068 skipped
...@@ -48,6 +48,9 @@ def main(): ...@@ -48,6 +48,9 @@ def main():
parser.add_argument('--transaction-id', nargs=1, dest='transaction_id', parser.add_argument('--transaction-id', nargs=1, dest='transaction_id',
type=int, required=False, type=int, required=False,
help="Additional parameter for notification-url") help="Additional parameter for notification-url")
parser.add_argument('--max-run', dest='max_run',
type=int, default=1, required=False,
help="Run executable until it ends correctly, in a limit of max-run times")
# Verbose mode # Verbose mode
parser.add_argument('--instance-root-name', dest='instance_root_name', parser.add_argument('--instance-root-name', dest='instance_root_name',
...@@ -74,28 +77,35 @@ def main(): ...@@ -74,28 +77,35 @@ def main():
saveStatus('STARTED') saveStatus('STARTED')
try: if args.max_run <= 0:
content = subprocess.check_output( print "--max-run argument takes a strictely positive number as argument"
args.executable[0], sys.exit(-1)
stderr=subprocess.STDOUT
) while args.max_run > 0:
exit_code = 0 try:
content = ("OK</br><p>%s ran successfully</p>" content = subprocess.check_output(
"<p>Output is: </p><pre>%s</pre>" % (
args.executable[0],
content.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
))
saveStatus('FINISHED')
except subprocess.CalledProcessError as e:
saveStatus('ERROR')
content = e.output
exit_code = e.returncode
content = ("FAILURE</br><p>%s Failed with returncode <em>%d</em>.</p>"
"<p>Output is: </p><pre>%s</pre>" % (
args.executable[0], args.executable[0],
exit_code, stderr=subprocess.STDOUT
content.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;') )
)) exit_code = 0
content = ("OK</br><p>%s ran successfully</p>"
"<p>Output is: </p><pre>%s</pre>" % (
args.executable[0],
content.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
))
saveStatus('FINISHED')
break
except subprocess.CalledProcessError as e:
args.max_run -= 1
saveStatus('ERROR')
content = e.output
exit_code = e.returncode
content = ("FAILURE</br><p>%s Failed with returncode <em>%d</em>.</p>"
"<p>Output is: </p><pre>%s</pre>" % (
args.executable[0],
exit_code,
content.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
))
print content print content
......
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