~proc_get_job
~proc_set_variables
~proc_get_job_names
+ ~proc_test_variables
(Rpc_server.Unix addr)
Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *)
Rpc.Socket
(* Which jobs need to be re-evaluated? *)
let jobs = Whenstate.get_dependencies !state [name] in
- let state' = reevaluate_whenjobs !state jobs in
+ let jobnames, state' = reevaluate_whenjobs !state jobs in
+ let state' = run_whenjobs state' jobnames in
state := state';
`ok
(* Which jobs need to be re-evaluated? *)
let jobs = Whenstate.get_dependencies !state (List.map fst vars) in
- let state' = reevaluate_whenjobs !state jobs in
+ let jobnames, state' = reevaluate_whenjobs !state jobs in
+ let state' = run_whenjobs state' jobnames in
state := state';
`ok
and proc_get_job_names () =
Array.of_list (Whenstate.get_job_names !state)
+and proc_test_variables vars =
+ (* This is the same as proc_set_variables, except that it doesn't
+ * update the state, it just returns the jobs that *would* run if
+ * these variables were set to these values.
+ *)
+ let vars = Array.map (
+ fun { Whenproto_aux.sv_name = name; sv_value = value } ->
+ name, variable_of_rpc value
+ ) vars in
+ let vars = Array.to_list vars in
+
+ if !debug then
+ Syslog.notice "remote call: test_variables (%s)"
+ (String.concat " "
+ (List.map (
+ fun (name, value) ->
+ sprintf "%s=%s" name (string_of_variable value)
+ ) vars));
+
+ List.iter (fun (name, _) -> check_valid_variable_name name) vars;
+
+ (* Update all the variables atomically. *)
+ let state = List.fold_left (
+ fun s (name, value) -> Whenstate.set_variable s name value
+ ) !state vars in
+
+ (* Which jobs WOULD be re-evaluated? *)
+ let jobs = Whenstate.get_dependencies state (List.map fst vars) in
+ let jobnames, _ = reevaluate_whenjobs state jobs in
+
+ (* Return the names. *)
+ Array.of_list jobnames
+
(* Reload the jobs file. *)
and reload_file () =
let file = sprintf "%s/jobs.cmo" !jobsdir in
(* Re-evaluate all when jobs. *)
let jobs = Whenstate.get_whenjobs !state in
- let state' = reevaluate_whenjobs ~onload:true !state jobs in
+ let jobnames, state' = reevaluate_whenjobs ~onload:true !state jobs in
+ let state' = run_whenjobs state' jobnames in
state := state';
(* Schedule the next every job to run. *)
schedule_next_everyjob ()
(* Re-evaluate each when-statement job, in a loop until we reach
- * a fixpoint. Run the jobs and return the updated state.
+ * a fixpoint. Return the list of job names that should run and
+ * the updated state.
*)
and reevaluate_whenjobs ?onload state jobs =
let rec loop (set, state) jobs =
(* Ensure the jobs always run in predictable (name) order. *)
let jobnames = List.sort compare_jobnames jobnames in
+ jobnames, state
+and run_whenjobs state jobnames =
(* Run the jobs. *)
let jobs = List.map (Whenstate.get_job state) jobnames in
List.fold_left run_job state jobs