Add a $JOBSERIAL environment variable when jobs run.
[whenjobs.git] / daemon / daemon.ml
index a6cc2fa..a8bd514 100644 (file)
@@ -18,6 +18,7 @@
 
 open Whenutils
 
 
 open Whenutils
 
+open Big_int
 open Unix
 open Printf
 
 open Unix
 open Printf
 
@@ -80,7 +81,12 @@ let rec init j d =
   );
 
   (* Handle SIGCHLD to clean up jobs. *)
   );
 
   (* Handle SIGCHLD to clean up jobs. *)
-  Sys.set_signal Sys.sigchld (Sys.Signal_handle handle_sigchld)
+  Sys.set_signal Sys.sigchld (Sys.Signal_handle handle_sigchld);
+
+  (* Initialize the variables.  XXX Eventually this will be saved
+   * and loaded from a persistent store.
+   *)
+  variables := StringMap.add "JOBSERIAL" (T_int zero_big_int) !variables
 
 and proc_reload_file () =
   if !debug then Syslog.notice "remote call: reload_file";
 
 and proc_reload_file () =
   if !debug then Syslog.notice "remote call: reload_file";
@@ -291,7 +297,18 @@ and string_of_time_t t =
     tm.tm_hour tm.tm_min tm.tm_sec
 
 and run_job job =
     tm.tm_hour tm.tm_min tm.tm_sec
 
 and run_job job =
-  Syslog.notice "running %s" job.job_name;
+  let () =
+    (* Increment JOBSERIAL. *)
+    let serial =
+      match StringMap.find "JOBSERIAL" !variables with
+      | T_int serial ->
+        let serial = succ_big_int serial in
+        variables := StringMap.add "JOBSERIAL" (T_int serial) !variables;
+        serial
+      | _ -> assert false in
+
+    Syslog.notice "running %s (JOBSERIAL=%s)"
+      job.job_name (string_of_big_int serial) in
 
   (* Create a temporary directory.  The current directory of the job
    * will be in this directory.  The directory is removed when the
 
   (* Create a temporary directory.  The current directory of the job
    * will be in this directory.  The directory is removed when the