-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
~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
| 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
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;
"--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";
);
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.
);
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;
whenjobs --jobs
whenjobs --cancel serial
whenjobs --start "name"
+ whenjobs --tail serial
=head1 DESCRIPTION
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.