Commit 7421df8e authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli.JobExecutor: Feedback function for info output



This will be used in the watcher where we don't want to
pollute stdout unless in debug mode.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 2be7c4cc
......@@ -3016,6 +3016,10 @@ class JobExecutor(object):
self.jobs = []
self.opts = opts
self.feedback_fn = feedback_fn
if feedback_fn:
self._info_fn = feedback_fn
else:
self._info_fn = ToStdout
self._counter = itertools.count()
@staticmethod
......@@ -3097,31 +3101,33 @@ class JobExecutor(object):
if self.verbose:
ok_jobs = [row[2] for row in self.jobs if row[1]]
if ok_jobs:
ToStdout("Submitted jobs %s", utils.CommaJoin(ok_jobs))
self._info_fn("Submitted jobs %s", utils.CommaJoin(ok_jobs))
# first, remove any non-submitted jobs
self.jobs, failures = compat.partition(self.jobs, lambda x: x[1])
for idx, _, jid, name in failures:
ToStderr("Failed to submit job%s: %s", self._IfName(name, " for %s"), jid)
self._info_fn("Failed to submit job%s: %s",
self._IfName(name, " for %s"), jid)
results.append((idx, False, jid))
while self.jobs:
(idx, _, jid, name) = self._ChooseJob()
ToStdout("Waiting for job %s%s ...", jid, self._IfName(name, " for %s"))
self._info_fn("Waiting for job %s%s ...",
jid, self._IfName(name, " for %s"))
try:
job_result = PollJob(jid, cl=self.cl, feedback_fn=self.feedback_fn)
success = True
except errors.JobLost, err:
_, job_result = FormatError(err)
ToStderr("Job %s%s has been archived, cannot check its result",
jid, self._IfName(name, " for %s"))
self._info_fn("Job %s%s has been archived, cannot check its result",
jid, self._IfName(name, " for %s"))
success = False
except (errors.GenericError, luxi.ProtocolError), err:
_, job_result = FormatError(err)
success = False
# the error message will always be shown, verbose or not
ToStderr("Job %s%s has failed: %s",
jid, self._IfName(name, " for %s"), job_result)
self._info_fn("Job %s%s has failed: %s",
jid, self._IfName(name, " for %s"), job_result)
results.append((idx, success, job_result))
......@@ -3145,9 +3151,9 @@ class JobExecutor(object):
self.SubmitPending()
for _, status, result, name in self.jobs:
if status:
ToStdout("%s: %s", result, name)
self._info_fn("%s: %s", result, name)
else:
ToStderr("Failure for %s: %s", name, result)
self._info_fn("Failure for %s: %s", name, result)
return [row[1:3] for row in self.jobs]
......
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