From 03b83c1a4bab53d8914c6946ad892bca30df09d0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 29 Feb 2012 15:53:04 +0000 Subject: [PATCH] Add 'whenjobs --tail ' to tail output messages from jobs. --- TODO | 3 --- daemon/daemon.ml | 13 +++++++++++++ lib/whenproto.x | 1 + tools/whenjobs.ml | 22 ++++++++++++++++++++++ tools/whenjobs.pod | 6 ++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 88bd0ad..391136b 100644 --- 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 diff --git a/daemon/daemon.ml b/daemon/daemon.ml index 925ad7e..6e6a5fd 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -78,6 +78,7 @@ let rec init j d = ~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 @@ -167,6 +168,18 @@ and proc_start_job jobname = | 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 diff --git a/lib/whenproto.x b/lib/whenproto.x index 280265d..5754821 100644 --- a/lib/whenproto.x +++ b/lib/whenproto.x @@ -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 get_job (string_big_int) = 9; } = 1; } = 0x20008081; diff --git a/tools/whenjobs.ml b/tools/whenjobs.ml index c792e26..be38f67 100644 --- a/tools/whenjobs.ml +++ b/tools/whenjobs.ml @@ -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"; + "--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"; @@ -220,6 +221,14 @@ Options: ); 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. @@ -421,6 +430,19 @@ and start_job name = ); 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; diff --git a/tools/whenjobs.pod b/tools/whenjobs.pod index 25dff40..466bdb1 100644 --- a/tools/whenjobs.pod +++ b/tools/whenjobs.pod @@ -29,6 +29,7 @@ Examine running jobs: whenjobs --jobs whenjobs --cancel serial whenjobs --start "name" + whenjobs --tail serial =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. +=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. -- 1.8.3.1