let set = loop StringSet.empty jobnames in
let jobnames = StringSet.elements set in
(* Ensure the jobs always run in predictable (name) order. *)
- let jobnames = List.sort compare jobnames in
+ let jobnames = List.sort compare_jobnames jobnames in
List.iter run_job
(List.map (fun jobname -> StringMap.find jobname !jobs) jobnames)
if jobs <> [] then (
(* Ensure the jobs always run in predictable (name) order. *)
let jobs =
- List.sort (fun { job_name = a } { job_name = b } -> compare a b) jobs in
+ List.sort (fun {job_name = a} {job_name = b} -> compare_jobnames a b)
+ jobs in
if !debug then
Syslog.notice "scheduling job(s) %s to run at %s"
let cmd = sprintf "rm -rf '%s'" dir in
ignore (Sys.command cmd)
+(* Intelligent comparison of job names. *)
+and compare_jobnames name1 name2 =
+ try
+ let len1 = String.length name1
+ and len2 = String.length name2 in
+ if len1 > 4 && len2 > 4 &&
+ String.sub name1 0 4 = "job$" && String.sub name2 0 4 = "job$"
+ then (
+ let i1 = int_of_string (String.sub name1 4 (len1-4)) in
+ let i2 = int_of_string (String.sub name2 4 (len2-4)) in
+ compare i1 i2
+ )
+ else raise Not_found
+ with _ ->
+ compare name1 name2
+
let main_loop () =
Unixqueue.run esys