Commit 5299e61f authored by Iustin Pop's avatar Iustin Pop
Browse files

cli.JobExecutor: poll jobs in execution order

… rather than submission order. The results are still returned in the
submission order, and for this we needed to track internally the index
of the submission.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarGuido Trotter <>
parent 2de64672
......@@ -1813,8 +1813,31 @@ class JobExecutor(object):
results =[row[1] for row in self.queue])
for ((status, data), (name, _)) in zip(results, self.queue):, data, name))
for (idx, ((status, data), (name, _))) in enumerate(zip(results,
self.queue)):, status, data, name))
def _ChooseJob(self):
"""Choose a non-waiting/queued job to poll next.
assert, "_ChooseJob called with empty job list"
result =[i[2] for i in], ["status"])
assert result
for job_data, status in zip(, result):
if status[0] in (constants.JOB_STATUS_QUEUED,
# job is still waiting
# good candidate found
return job_data
# no job found
def GetResults(self):
"""Wait for and return the results of all jobs.
......@@ -1829,16 +1852,19 @@ class JobExecutor(object):
results = []
if self.verbose:
ok_jobs = [row[1] for row in if row[0]]
ok_jobs = [row[2] for row in if row[1]]
if ok_jobs:
ToStdout("Submitted jobs %s", utils.CommaJoin(ok_jobs))
for submit_status, jid, name in
if not submit_status:
# first, remove any non-submitted jobs, failures = utils.partition(, lambda x: x[1])
for idx, _, jid, name in failures:
ToStderr("Failed to submit job for %s: %s", name, jid)
results.append((False, jid))
if self.verbose:
ToStdout("Waiting for job %s for %s...", jid, name)
results.append((idx, False, jid))
(idx, _, jid, name) = self._ChooseJob()
ToStdout("Waiting for job %s for %s...", jid, name)
job_result = PollJob(jid,
success = True
......@@ -1848,7 +1874,12 @@ class JobExecutor(object):
# the error message will always be shown, verbose or not
ToStderr("Job %s for %s has failed: %s", jid, name, job_result)
results.append((success, job_result))
results.append((idx, success, job_result))
# sort based on the index, then drop it
results = [i[1:] for i in results]
return results
def WaitOrShow(self, wait):
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