(* Which jobs need to be re-evaluated? *)
let jobs = Whenstate.get_dependencies !state [name] in
- reevaluate_whenjobs jobs;
+ let state' = reevaluate_whenjobs !state jobs in
+ state := state';
`ok
with
and proc_start_job jobname =
try
let job = Whenstate.get_job !state jobname in
- run_job job;
+ let state' = run_job !state job in
+ state := state';
`ok
with
| Not_found -> `error "job not found"
(* Which jobs need to be re-evaluated? *)
let jobs = Whenstate.get_dependencies !state (List.map fst vars) in
- reevaluate_whenjobs jobs;
+ let state' = reevaluate_whenjobs !state jobs in
+ state := state';
`ok
with
state := s;
(* Re-evaluate all when jobs. *)
- reevaluate_whenjobs ~onload:true (Whenstate.get_whenjobs !state);
+ let jobs = Whenstate.get_whenjobs !state in
+ let state' = reevaluate_whenjobs ~onload:true !state jobs 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 those that need to be run.
+ * a fixpoint. Run the jobs and return the updated state.
*)
-and reevaluate_whenjobs ?onload jobs =
- let rec loop set jobs =
- let set' =
+and reevaluate_whenjobs ?onload state jobs =
+ let rec loop (set, state) jobs =
+ let set', state' =
List.fold_left (
- fun set job ->
+ fun (set, state) job ->
let r, state' =
- try Whenstate.evaluate_whenjob ?onload !state job
+ try Whenstate.evaluate_whenjob ?onload state job
with Invalid_argument err | Failure err ->
Syslog.error "error evaluating job %s (at %s): %s"
job.job_name (Camlp4.PreCast.Ast.Loc.to_string job.job_loc) err;
- false, !state in
-
- state := state';
+ false, state in
if !debug then
Syslog.notice "evaluate %s -> %b\n" job.job_name r;
- if r then StringSet.add job.job_name set else set
- ) set jobs in
+ (if r then StringSet.add job.job_name set else set), state'
+ ) (set, state) jobs in
+ (* reached a fixpoint? *)
if StringSet.compare set set' <> 0 then
- loop set' jobs
+ loop (set', state') jobs
else
- set'
+ (set', state')
in
- let set = loop StringSet.empty jobs in
+ let set, state = loop (StringSet.empty, state) jobs in
let jobnames = StringSet.elements set in
(* Ensure the jobs always run in predictable (name) order. *)
let jobnames = List.sort compare_jobnames jobnames in
(* Run the jobs. *)
- List.iter run_job (List.map (Whenstate.get_job !state) jobnames)
+ let jobs = List.map (Whenstate.get_job state) jobnames in
+ List.fold_left run_job state jobs
(* Schedule the next every-statement job to run, if there is one. We
* look at the every jobs, work out the time that each must run at,
let t_diff = if t_diff < 0. then 0. else t_diff in
let run_jobs () =
delete_timer_group (); (* Delete the timer. *)
- List.iter run_job jobs;
+ let state' = List.fold_left run_job !state jobs in
+ state := state';
schedule_next_everyjob ()
in
Unixqueue.weak_once esys g t_diff run_jobs;
Unixqueue.clear esys g;
timer_group := None
-and run_job job =
+and run_job state job =
(* Increment JOBSERIAL. *)
- let serial =
- match Whenstate.get_variable !state "JOBSERIAL" with
+ let serial, state =
+ match Whenstate.get_variable state "JOBSERIAL" with
| T_int serial ->
let serial = succ_big_int serial in
- state := Whenstate.set_variable !state "JOBSERIAL" (T_int serial);
- serial
+ let state' = Whenstate.set_variable state "JOBSERIAL" (T_int serial) in
+ serial, state'
| _ -> assert false in
(* Call the pre-condition script. Note this may decide not to run
let preinfo = {
pi_job_name = job.job_name;
pi_serial = serial;
- pi_variables = Whenstate.get_variables !state;
+ pi_variables = Whenstate.get_variables state;
pi_running = !rs;
} in
pre preinfo
(* Set environment variables corresponding to each variable. *)
List.iter
(fun (name, value) -> putenv name (string_of_variable value))
- (Whenstate.get_variables !state);
+ (Whenstate.get_variables state);
(* Set the $JOBNAME environment variable. *)
putenv "JOBNAME" job.job_name;
* can clean up when the child exits.
*)
runningmap := IntMap.add pid (job, dir, serial, time ()) !runningmap;
- serialmap := BigIntMap.add serial pid !serialmap
+ serialmap := BigIntMap.add serial pid !serialmap;
+
+ state
)
else (
Syslog.notice "not running %s (JOBSERIAL=%s) because pre() condition returned false"
job.job_name (string_of_big_int serial);
+
+ state
)
and tmpdir () =