Add 'whenjobs --tail <serial>' to tail output messages from jobs.
authorRichard W.M. Jones <rjones@redhat.com>
Wed, 29 Feb 2012 15:53:04 +0000 (15:53 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Wed, 29 Feb 2012 15:57:49 +0000 (15:57 +0000)
TODO
daemon/daemon.ml
lib/whenproto.x
tools/whenjobs.ml
tools/whenjobs.pod

diff --git a/TODO b/TODO
index 88bd0ad..391136b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,3 @@
-Allow the output of a job to be listed.  This is pretty easy since we
-know the tmpdir and the output file.
-
 For Whentools.once and Whentools.max:
 
  - Add a ~group parameter so we can run no more than "n" jobs in one
 For Whentools.once and Whentools.max:
 
  - Add a ~group parameter so we can run no more than "n" jobs in one
index 925ad7e..6e6a5fd 100644 (file)
@@ -78,6 +78,7 @@ let rec init j d =
       ~proc_get_jobs
       ~proc_cancel_job
       ~proc_start_job
       ~proc_get_jobs
       ~proc_cancel_job
       ~proc_start_job
+      ~proc_get_job
       (Rpc_server.Unix addr)
       Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *)
       Rpc.Socket
       (Rpc_server.Unix addr)
       Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *)
       Rpc.Socket
@@ -167,6 +168,18 @@ and proc_start_job jobname =
   | Not_found -> `error "job not found"
   | exn -> `error (Printexc.to_string exn)
 
   | Not_found -> `error "job not found"
   | exn -> `error (Printexc.to_string exn)
 
+and proc_get_job serial =
+  try
+    let serial = big_int_of_string serial in
+    let pid = BigIntMap.find serial !serialmap in
+    let job, dir, serial, start_time = IntMap.find pid !runningmap in
+    { Whenproto_aux.job_name = job.job_name;
+      job_serial = string_of_big_int serial;
+      job_tmpdir = dir; job_start_time = Int64.of_float start_time }
+  with
+  | Not_found -> failwith "job not found"
+  | exn -> failwith (Printexc.to_string exn)
+
 (* Reload the jobs file. *)
 and reload_file () =
   let file = sprintf "%s/jobs.cmo" !jobsdir in
 (* Reload the jobs file. *)
 and reload_file () =
   let file = sprintf "%s/jobs.cmo" !jobsdir in
index 280265d..5754821 100644 (file)
@@ -90,5 +90,6 @@ program When {
     job_list get_jobs (void) = 6;
     status cancel_job (string_big_int) = 7;
     status start_job (job_name) = 8;
     job_list get_jobs (void) = 6;
     status cancel_job (string_big_int) = 7;
     status start_job (job_name) = 8;
+    job get_job (string_big_int) = 9;
   } = 1;
 } = 0x20008081;
   } = 1;
 } = 0x20008081;
index c792e26..be38f67 100644 (file)
@@ -95,6 +95,7 @@ let rec main () =
     "--lib", Arg.Set_string libdir, "dir Specify directory that contains pa_when.cmo";
     "--set", Arg.Unit (set_mode `Set), " Set the variable";
     "--start", Arg.Unit (set_mode `Start), "name Start a job manually";
     "--lib", Arg.Set_string libdir, "dir Specify directory that contains pa_when.cmo";
     "--set", Arg.Unit (set_mode `Set), " Set the variable";
     "--start", Arg.Unit (set_mode `Start), "name Start a job manually";
+    "--tail", Arg.Unit (set_mode `Tail), "serial Tail job output";
     "--type", Arg.Set_string typ, "bool|int|float|string|unit Set the variable type";
     "--upload", Arg.Unit (set_mode `Upload), " Upload the script";
     "--variables", Arg.Unit (set_mode `Variables), " Display all variables and values";
     "--type", Arg.Set_string typ, "bool|int|float|string|unit Set the variable type";
     "--upload", Arg.Unit (set_mode `Upload), " Upload the script";
     "--variables", Arg.Unit (set_mode `Variables), " Display all variables and values";
@@ -220,6 +221,14 @@ Options:
     );
     start_job (List.hd args)
 
     );
     start_job (List.hd args)
 
+  | Some `Tail ->
+    if List.length args != 1 then (
+      eprintf "whenjobs --tail serial\n";
+      suggest_help ();
+      exit 1
+    );
+    tail (List.hd args)
+
 and edit_file () =
   (* If there is no initial file, create an empty one containing the
    * tutorial.
 and edit_file () =
   (* If there is no initial file, create an empty one containing the
    * tutorial.
@@ -421,6 +430,19 @@ and start_job name =
   );
   stop_client client
 
   );
   stop_client client
 
+  (* This only works for local.  If we ever make whenjobs work
+   * remotely we'll have to change the implementation to use
+   * the server.
+   *)
+and tail serial =
+  let client = start_client () in
+  let job = Whenproto_clnt.When.V1.get_job client serial in
+  stop_client client;
+  let cmd =
+    sprintf "tail -f %s/output.txt"
+      (Filename.quote job.Whenproto_aux.job_tmpdir) in
+  exit (Sys.command cmd)
+
 and unused_error args op =
   if args <> [] then (
     eprintf "whenjobs %s: unused parameters on the command line.\n" op;
 and unused_error args op =
   if args <> [] then (
     eprintf "whenjobs %s: unused parameters on the command line.\n" op;
index 25dff40..466bdb1 100644 (file)
@@ -29,6 +29,7 @@ Examine running jobs:
  whenjobs --jobs
  whenjobs --cancel serial
  whenjobs --start "name"
  whenjobs --jobs
  whenjobs --cancel serial
  whenjobs --start "name"
+ whenjobs --tail serial
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -176,6 +177,11 @@ Start the job immediately and unconditionally.
 This runs the job even if its normal preconditions are not met.  This
 may cause unexpected results, so use with caution.
 
 This runs the job even if its normal preconditions are not met.  This
 may cause unexpected results, so use with caution.
 
+=item B<--tail> serial
+
+Tail the output of the running job identified by its serial number.
+Use the I<--jobs> flag to get a list of running jobs.
+
 =item B<--upload>
 
 Compile the jobs script and upload it to the daemon, without editing.
 =item B<--upload>
 
 Compile the jobs script and upload it to the daemon, without editing.