X-Git-Url: http://git.annexia.org/?p=whenjobs.git;a=blobdiff_plain;f=lib%2Fwhenexpr.ml;h=1301e5e401a79c2f34f57cde213aa50fb073b359;hp=df1665befa385cb0052825065f605bf20a9f3669;hb=HEAD;hpb=cffe87109d9c868eefd48f7d5255a4863a578e4d diff --git a/lib/whenexpr.ml b/lib/whenexpr.ml index df1665b..1301e5e 100644 --- a/lib/whenexpr.ml +++ b/lib/whenexpr.ml @@ -41,6 +41,7 @@ type whenexpr = | Expr_eq of whenexpr * whenexpr | Expr_ge of whenexpr * whenexpr | Expr_gt of whenexpr * whenexpr + | Expr_ne of whenexpr * whenexpr | Expr_not of whenexpr | Expr_add of whenexpr * whenexpr | Expr_sub of whenexpr * whenexpr @@ -83,16 +84,6 @@ type shell_script = { sh_script : string; } -type result = { - res_job_name : string; - res_serial : Big_int.big_int; - res_code : int; - res_tmpdir : string; - res_output : string; -} - -type cleanup = result -> unit - type variable = | T_unit | T_bool of bool @@ -116,6 +107,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 @@ -123,7 +139,8 @@ type job_cond = type job = { job_loc : Loc.t; job_name : string; - job_cleanup : cleanup option; + job_pre : pre option; + job_post : post option; job_cond : job_cond; job_script : shell_script; } @@ -196,6 +213,9 @@ and expr_of_iexpr _loc = function | IExpr_app (">", exprs) -> two_params _loc ">" exprs (fun e1 e2 -> Expr_gt (e1, e2)) + | IExpr_app (("!="|"<>"), exprs) -> + two_params _loc "<>" exprs (fun e1 e2 -> Expr_ne (e1, e2)) + | IExpr_app ("!", exprs) -> one_param _loc "!" exprs (fun e1 -> Expr_not e1) @@ -278,6 +298,8 @@ let rec string_of_whenexpr = function sprintf "%s >= %s" (string_of_whenexpr e1) (string_of_whenexpr e2) | Expr_gt (e1, e2) -> sprintf "%s > %s" (string_of_whenexpr e1) (string_of_whenexpr e2) + | Expr_ne (e1, e2) -> + sprintf "%s <> %s" (string_of_whenexpr e1) (string_of_whenexpr e2) | Expr_not e -> sprintf "! %s" (string_of_whenexpr e) | Expr_add (e1, e2) -> sprintf "%s + %s" (string_of_whenexpr e1) (string_of_whenexpr e2) @@ -320,6 +342,7 @@ let rec dependencies_of_whenexpr = function | Expr_eq (e1, e2) | Expr_ge (e1, e2) | Expr_gt (e1, e2) + | Expr_ne (e1, e2) | Expr_add (e1, e2) | Expr_sub (e1, e2) | Expr_mul (e1, e2) @@ -403,6 +426,14 @@ let rec eval_whenexpr variables prev_variables onload = function else T_bool false + | Expr_ne (e1, e2) -> + let e1 = eval_whenexpr variables prev_variables onload e1 + and e2 = eval_whenexpr variables prev_variables onload e2 in + if compare_values e1 e2 <> 0 then + T_bool true + else + T_bool false + | Expr_not e -> if not (eval_whenexpr_as_bool variables prev_variables onload e) then T_bool true