Revision 5299e61f
b/lib/cli.py | ||
---|---|---|
1813 | 1813 |
|
1814 | 1814 |
""" |
1815 | 1815 |
results = self.cl.SubmitManyJobs([row[1] for row in self.queue]) |
1816 |
for ((status, data), (name, _)) in zip(results, self.queue): |
|
1817 |
self.jobs.append((status, data, name)) |
|
1816 |
for (idx, ((status, data), (name, _))) in enumerate(zip(results, |
|
1817 |
self.queue)): |
|
1818 |
self.jobs.append((idx, status, data, name)) |
|
1819 |
|
|
1820 |
def _ChooseJob(self): |
|
1821 |
"""Choose a non-waiting/queued job to poll next. |
|
1822 |
|
|
1823 |
""" |
|
1824 |
assert self.jobs, "_ChooseJob called with empty job list" |
|
1825 |
|
|
1826 |
result = self.cl.QueryJobs([i[2] for i in self.jobs], ["status"]) |
|
1827 |
assert result |
|
1828 |
|
|
1829 |
for job_data, status in zip(self.jobs, result): |
|
1830 |
if status[0] in (constants.JOB_STATUS_QUEUED, |
|
1831 |
constants.JOB_STATUS_WAITLOCK, |
|
1832 |
constants.JOB_STATUS_CANCELING): |
|
1833 |
# job is still waiting |
|
1834 |
continue |
|
1835 |
# good candidate found |
|
1836 |
self.jobs.remove(job_data) |
|
1837 |
return job_data |
|
1838 |
|
|
1839 |
# no job found |
|
1840 |
return self.jobs.pop(0) |
|
1818 | 1841 |
|
1819 | 1842 |
def GetResults(self): |
1820 | 1843 |
"""Wait for and return the results of all jobs. |
... | ... | |
1829 | 1852 |
self.SubmitPending() |
1830 | 1853 |
results = [] |
1831 | 1854 |
if self.verbose: |
1832 |
ok_jobs = [row[1] for row in self.jobs if row[0]]
|
|
1855 |
ok_jobs = [row[2] for row in self.jobs if row[1]]
|
|
1833 | 1856 |
if ok_jobs: |
1834 | 1857 |
ToStdout("Submitted jobs %s", utils.CommaJoin(ok_jobs)) |
1835 |
for submit_status, jid, name in self.jobs: |
|
1836 |
if not submit_status: |
|
1858 |
|
|
1859 |
# first, remove any non-submitted jobs |
|
1860 |
self.jobs, failures = utils.partition(self.jobs, lambda x: x[1]) |
|
1861 |
for idx, _, jid, name in failures: |
|
1837 | 1862 |
ToStderr("Failed to submit job for %s: %s", name, jid) |
1838 |
results.append((False, jid)) |
|
1839 |
continue |
|
1840 |
if self.verbose: |
|
1841 |
ToStdout("Waiting for job %s for %s...", jid, name) |
|
1863 |
results.append((idx, False, jid)) |
|
1864 |
|
|
1865 |
while self.jobs: |
|
1866 |
(idx, _, jid, name) = self._ChooseJob() |
|
1867 |
ToStdout("Waiting for job %s for %s...", jid, name) |
|
1842 | 1868 |
try: |
1843 | 1869 |
job_result = PollJob(jid, cl=self.cl) |
1844 | 1870 |
success = True |
... | ... | |
1848 | 1874 |
# the error message will always be shown, verbose or not |
1849 | 1875 |
ToStderr("Job %s for %s has failed: %s", jid, name, job_result) |
1850 | 1876 |
|
1851 |
results.append((success, job_result)) |
|
1877 |
results.append((idx, success, job_result)) |
|
1878 |
|
|
1879 |
# sort based on the index, then drop it |
|
1880 |
results.sort() |
|
1881 |
results = [i[1:] for i in results] |
|
1882 |
|
|
1852 | 1883 |
return results |
1853 | 1884 |
|
1854 | 1885 |
def WaitOrShow(self, wait): |
Also available in: Unified diff