Skip to content
Snippets Groups Projects
Commit 1d0c9973 authored by Jürg Billeter's avatar Jürg Billeter
Browse files

WIP: sandbox/_sandboxremote.py: Implement command batching

parent 70d56a40
No related branches found
No related tags found
Loading
Pipeline #32043110 failed
......@@ -19,6 +19,7 @@
# Jim MacArthur <jim.macarthur@codethink.co.uk>
import os
import shlex
from urllib.parse import urlparse
import grpc
......@@ -230,3 +231,39 @@ class SandboxRemote(Sandbox):
self.process_job_output(action_result.output_directories, action_result.output_files)
return 0
def run_queue(self, flags, *, cwd=None, env=None):
queue = self._queue
self._queue = []
script = ""
i = 0
for entry in queue:
if entry.command:
cmdline = ' '.join(shlex.quote(cmd) for cmd in entry.command)
script += "({})\n".format(cmdline)
script += "RETVAL=$?\n"
script += "if [ $RETVAL -ne 0 ] ; then\n"
# Report failing command and exit code to stderr (and then back to client)
script += " echo -e '\nbst-command-failure:' {} $RETVAL >&2\n".format(i)
script += " exit 1\n"
script += "fi\n"
i += 1
exit_code = self.run(['sh', '-c', script], flags, cwd=cwd, env=env)
if exit_code != 0:
# TODO get failed command and exit code from stderr
failed_command = 0
command_exit_code = 1
i = 0
for entry in queue:
entry.start_callback()
if exit_code == 0 or i < failed_command:
# Command succeeded
entry.complete_callback(0)
else:
# Command failed
entry.complete_callback(command_exit_code)
break
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment