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

WIP: sandbox/_sandboxremote.py: Implement command batching

parent faa03f51
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# Jim MacArthur <jim.macarthur@codethink.co.uk> # Jim MacArthur <jim.macarthur@codethink.co.uk>
import os import os
import shlex
from urllib.parse import urlparse from urllib.parse import urlparse
import grpc import grpc
...@@ -227,3 +228,38 @@ class SandboxRemote(Sandbox): ...@@ -227,3 +228,38 @@ class SandboxRemote(Sandbox):
self.process_job_output(action_result.output_directories, action_result.output_files) self.process_job_output(action_result.output_directories, action_result.output_files)
return 0 return 0
def run_queue(self, flags, *, cwd=None, env=None):
queue = self._queue
self._queue = []
script = ""
i = 0
for entry in queue:
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