+ let r =
+ try
+ let client = start_client_no_exit () in
+ let r = Whenproto_clnt.When.V1.ping_daemon client () in
+ stop_client client;
+ r = `ok
+ with
+ exn -> false in
+ print_endline (if r then "up" else "down")
+
+and jobs () =
+ let client = start_client () in
+ let jobs = Whenproto_clnt.When.V1.get_jobs client () in
+ stop_client client;
+
+ let cmp { Whenproto_aux.job_name = name1; job_serial = serial1 }
+ { Whenproto_aux.job_name = name2; job_serial = serial2 } =
+ let i = compare name1 name2 in
+ if i <> 0 then i
+ else
+ compare_big_int (big_int_of_string serial1) (big_int_of_string serial2)
+ in
+ Array.sort cmp jobs;
+
+ Array.iter (
+ fun { Whenproto_aux.job_serial = serial; job_name = name;
+ job_tmpdir = tmpdir; job_start_time = time } ->
+ printf "%s %s\n\trunning in: %s\n\tstarted at: %s\n"
+ serial name tmpdir
+ (string_of_time_t ~localtime:true (Int64.to_float time))
+ ) jobs
+
+and cancel_job serial =
+ let client = start_client () in
+ (match Whenproto_clnt.When.V1.cancel_job client serial with
+ | `ok -> ()
+ | `error msg ->
+ eprintf "whenjobs: cancel-job: %s\n" msg;
+ suggest_check_server_logs ();
+ exit 1
+ );
+ stop_client client
+
+and start_job name =
+ let client = start_client () in
+ (match Whenproto_clnt.When.V1.start_job client name with
+ | `ok -> ()
+ | `error msg ->
+ eprintf "whenjobs: start-job: %s\n" msg;
+ suggest_check_server_logs ();
+ exit 1
+ );
+ 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 job_names () =
+ let client = start_client () in
+ let names = Whenproto_clnt.When.V1.get_job_names client () in
+ stop_client client;
+ Array.iter print_endline names