From: Richard W.M. Jones Date: Tue, 21 Feb 2012 13:57:07 +0000 (+0000) Subject: Compare job names intelligently, so "job$9" < "job$10". X-Git-Tag: 0.0.1~14 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=28d4576308b10064eda39827c419aa33e1041041;p=whenjobs.git Compare job names intelligently, so "job$9" < "job$10". --- 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