X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fdaemon.ml;h=bc4f51a2f1177e5be2692a233d7f2b850f9a55bc;hb=8582d10e7b131ffbfe1d92352e7df39230ce1124;hp=5b9fc3b8c6b9bc278229b6d384f8d3972c89bd14;hpb=c8bff8ac923645d517183b130158d61f85540b33;p=whenjobs.git diff --git a/daemon/daemon.ml b/daemon/daemon.ml index 5b9fc3b..bc4f51a 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -82,6 +82,8 @@ let rec init j d = ~proc_set_variables ~proc_get_job_names ~proc_test_variables + ~proc_ping_daemon + ~proc_whisper_variables (Rpc_server.Unix addr) Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *) Rpc.Socket @@ -97,7 +99,7 @@ let rec init j d = and proc_reload_file () = if !debug then Syslog.notice "remote call: reload_file"; - try reload_file (); `ok + try reload_files (); `ok with Failure err -> `error err and proc_set_variable (name, value) = @@ -256,9 +258,47 @@ and proc_test_variables vars = (* Return the names. *) Array.of_list jobnames -(* Reload the jobs file. *) -and reload_file () = - let file = sprintf "%s/jobs.cmo" !jobsdir in +and proc_ping_daemon () = `ok + +and proc_whisper_variables vars = + try + 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: whisper_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 s = List.fold_left ( + fun s (name, value) -> Whenstate.set_variable s name value + ) !state vars in + state := s; + + (* .. but don't reevaluate or run jobs. *) + + `ok + with + Failure msg -> `error msg + +(* Reload the jobs file(s). *) +and reload_files () = + (* Get dir/*.cmo (bytecode) or dir/*.cmxs (native code) *) + let suffix = if not Dynlink.is_native then ".cmo" else ".cmxs" in + let dir = !jobsdir in + let files = Array.to_list (Sys.readdir dir) in + let files = List.filter (fun file -> string_endswith file suffix) files in + let files = List.map (fun file -> dir // file) files in + let files = List.sort compare files in (* As we are reloading the file, we want to create a new state * that has no jobs, but has all the variables from the previous @@ -269,9 +309,10 @@ and reload_file () = let s = try - Dynlink.loadfile file; + List.iter Dynlink.loadfile files; let s = Whenfile.get_state () in - Syslog.notice "loaded %d job(s) from %s" (Whenstate.nr_jobs s) file; + Syslog.notice "loaded %d job(s) from %d file(s)" + (Whenstate.nr_jobs s) (List.length files); s with | Dynlink.Error err ->