X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=lib%2Fwhenexpr.ml;h=c2ffa334be9c77404579d21d23a15f4192c6ce66;hb=d0eb02dfe7ab7db2f9e67c4313a1cad3b0ce4d93;hp=8ccde2cedd7c1c56b456317faeea52c763c8bceb;hpb=5c7aa66dbdb32b4fc11d0f72a4cc028c7bfb1b55;p=whenjobs.git diff --git a/lib/whenexpr.ml b/lib/whenexpr.ml index 8ccde2c..c2ffa33 100644 --- a/lib/whenexpr.ml +++ b/lib/whenexpr.ml @@ -106,6 +106,31 @@ let rpc_of_variable = function type variables = variable StringMap.t +type preinfo = { + pi_job_name : string; + pi_serial : Big_int.big_int; + pi_variables : (string * variable) list; + pi_running : preinfo_running_job list; +} +and preinfo_running_job = { + pirun_job_name : string; + pirun_serial : Big_int.big_int; + pirun_start_time : float; + pirun_pid : int; +} + +type result = { + res_job_name : string; + res_serial : Big_int.big_int; + res_code : int; + res_tmpdir : string; + res_output : string; + res_start_time : float; +} + +type pre = preinfo -> bool +type post = result -> unit + type job_cond = | When_job of whenexpr | Every_job of periodexpr @@ -113,6 +138,8 @@ type job_cond = type job = { job_loc : Loc.t; job_name : string; + job_pre : pre option; + job_post : post option; job_cond : job_cond; job_script : shell_script; } @@ -616,3 +643,22 @@ let next_periodexpr = let t0 = Date.make 1970 1 1 in let t' = Date.add t0 (Date.Period.month months) in Date.to_unixfloat t' + +let check_valid_variable_name name = + (* Don't permit certain names. *) + if name = "JOBSERIAL" then + failwith "JOBSERIAL variable cannot be set"; + + let len = String.length name in + if len = 0 then + failwith "variable name is an empty string"; + if name.[0] <> '_' && not (isalpha name.[0]) then + failwith "variable name must start with alphabetic character or underscore"; + + let rec loop i = + if i >= len then () + else if name.[i] <> '_' && not (isalnum name.[i]) then + failwith "variable name contains non-alphanumeric non-underscore character" + else loop (i+1) + in + loop 1