From 28d4576308b10064eda39827c419aa33e1041041 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 21 Feb 2012 13:57:07 +0000 Subject: [PATCH 1/1] Compare job names intelligently, so "job$9" < "job$10". --- daemon/daemon.ml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/daemon/daemon.ml b/daemon/daemon.ml index fd986fb..a6cc2fa 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -210,7 +210,7 @@ and reevaluate_whenjobs jobnames = 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) @@ -263,7 +263,8 @@ and schedule_next_everyjob () = 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" @@ -356,5 +357,21 @@ and cleanup_job job dir = 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 -- 1.8.3.1