Implement pre functions.
[whenjobs.git] / lib / whenexpr.mli
index 12ba584..7310387 100644 (file)
@@ -76,6 +76,34 @@ val rpc_of_variable : variable -> Whenproto_aux.variable
 type variables = variable Whenutils.StringMap.t
 (** A set of variables. *)
 
+type preinfo = {
+  pi_job_name : string;                 (** Job name. *)
+  pi_serial : Big_int.big_int;          (** Job serial number. *)
+  pi_variables : (string * variable) list; (** Variables set in job. *)
+  pi_running : preinfo_running_job list; (** List of running jobs. *)
+}
+and preinfo_running_job = {
+  pirun_job_name : string;              (** Running job name. *)
+  pirun_serial : Big_int.big_int;       (** Running job serial number. *)
+  pirun_start_time : float;             (** Running job start time. *)
+  pirun_pid : int;                      (** Running job process ID. *)
+}
+(** Information available to pre function before the job runs. *)
+
+type result = {
+  res_job_name : string;                (** Job name. *)
+  res_serial : Big_int.big_int;         (** Job serial number. *)
+  res_code : int;                       (** Return code from the script. *)
+  res_tmpdir : string;                  (** Temporary directory. *)
+  res_output : string;                  (** Filename of output from job. *)
+  res_start_time : float;               (** When the job started. *)
+}
+(** Result of the run of a job. *)
+
+type pre = preinfo -> bool
+type post = result -> unit
+(** Pre and post functions. *)
+
 type job_cond =
   | When_job of whenexpr                (** when ... : << >> *)
   | Every_job of periodexpr             (** every ... : << >> *)
@@ -83,6 +111,8 @@ type job_cond =
 type job = {
   job_loc : Camlp4.PreCast.Loc.t;
   job_name : string;
+  job_pre : pre option;
+  job_post : post option;
   job_cond : job_cond;
   job_script : shell_script;
 }
@@ -161,3 +191,7 @@ val next_periodexpr : float -> periodexpr -> float
     midnight UTC on the 1st day of the year when
     [(y - 1970) mod i == 0].  This returns midnight on the
     1st day of the next year > t. *)
+
+val check_valid_variable_name : string -> unit
+(** Check that [name] is a valid variable name that users are permitted
+    to set, and raise [Failure] if it is not.  *)