Add new command gnt_job wait
authorKlaus Aehlig <aehlig@google.com>
Thu, 23 May 2013 15:38:22 +0000 (17:38 +0200)
committerKlaus Aehlig <aehlig@google.com>
Tue, 11 Jun 2013 07:26:52 +0000 (09:26 +0200)
This command tacitly waits for a job to finish. In that
way, job dependency can also be handled in shell scripts.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/client/gnt_job.py
man/gnt-job.rst

index d8a9d27..ef26c0b 100644 (file)
@@ -440,6 +440,28 @@ def WatchJob(opts, args):
   return retcode
 
 
+def WaitJob(opts, args):
+  """Wait for a job to finish, not producing any output.
+
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: Contains the job ID
+  @rtype: int
+  @return: the desired exit code
+
+  """
+  job_id = args[0]
+
+  retcode = 0
+  try:
+    cli.PollJob(job_id, feedback_fn=lambda _: None)
+  except errors.GenericError, err:
+    (retcode, job_result) = cli.FormatError(err)
+    ToStderr("Job %s failed: %s", job_id, job_result)
+
+  return retcode
+
+
 _PENDING_OPT = \
   cli_option("--pending", default=None,
              action="store_const", dest="status_filter",
@@ -523,6 +545,9 @@ commands = {
     ShowJobs, [ArgJobId(min=1)], [],
     "<job-id> [<job-id> ...]",
     "Show detailed information about the specified jobs"),
+  "wait": (
+    WaitJob, [ArgJobId(min=1, max=1)], [],
+    "<job-id>", "Wait for a job to finish"),
   "watch": (
     WatchJob, [ArgJobId(min=1, max=1)], [],
     "<job-id>", "Follows a job and prints its output as it arrives"),
index 83a3361..196a3c5 100644 (file)
@@ -124,6 +124,14 @@ LIST-FIELDS
 Lists available fields for jobs.
 
 
+WAIT
+~~~~~
+
+**wait** {id}
+
+Wait for the job by the given *id* to finish; do not produce
+any output.
+
 WATCH
 ~~~~~