From 202649e56bd78fa662d8a79770b469766844529d Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Thu, 16 Nov 2017 19:33:48 +1100 Subject: [PATCH] Show time elapsed on current dir of running jobs --- TODO | 6 +++--- apiLib.sml | 2 ++ serverLib.sml | 25 +++++++++++++++++++------ worker.sml | 1 - 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 3794121..4253dea 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ -TODO: Show more information on directories in progress - - Could display the time spent so far (i.e., now - start time) - - Could display the average time spent on this directory in other running/stopped jobs +TODO: Show expected time required for a directory in progress + Can be calculated as the average time for this directory in other + stopped/running jobs TODO: Add interface to stop jobs. Rethink job categorisation. Should the job page have a link for cancelling that job? diff --git a/apiLib.sml b/apiLib.sml index 8364211..4cf24e0 100644 --- a/apiLib.sml +++ b/apiLib.sml @@ -251,6 +251,8 @@ fun read_job_type inp = else "master" end +val max_dir_length = 50 + datatype status = Pending | Success | Failure | Aborted fun read_status inp = diff --git a/serverLib.sml b/serverLib.sml index 4657b06..db77431 100644 --- a/serverLib.sml +++ b/serverLib.sml @@ -575,6 +575,8 @@ structure HTML = struct "for (var i = 0; i < ls.length; i++) {", "if (ls[i].getAttribute('class') == 'ago') {", "ls[i].innerHTML = ' [' + moment(ls[i].getAttribute('datetime')).fromNow() + ']';}", + "else if (ls[i].getAttribute('class') == 'since') {", + "ls[i].innerHTML = '[elapsed: ' + moment(ls[i].getAttribute('datetime')).fromNow(true) + ']';}", "else if (all) {", "ls[i].innerHTML = moment(ls[i].getAttribute('datetime')).format('", pretty_date_moment,"');}}}"] @@ -776,20 +778,31 @@ in format_rusage (Substring.string rest), "\n"] end handle Option => escape s + fun elapsed_time (acc as (dir_part::time_part::rest)) = + let in let + val prefix = " Starting " + val dir = extract_prefix_trimr prefix dir_part + (* val pad = CharVector.tabulate(max_dir_length - String.size dir,(fn _ => #" ")) *) + val (l,r) = Substring.splitAt (Substring.full time_part,6) + val line = String.concat [ + time_part, prefix, dir, " ", + Substring.string l, "class='since' ", Substring.string r, "\n" ] + in + line :: rest + end handle Option => acc | Subscript => acc end + | elapsed_time acc = acc fun loop acc = let val line = read_line() in let val (date,rest) = ReadJSON.bare_read_date (Substring.full line) - val line = - String.concat - [time date, - format_log_line (Substring.string rest)] + val acc = time date :: acc + val acc = format_log_line (Substring.string rest) :: acc in - loop (line::acc) + loop acc end handle Option => escape (TextIO.inputAll inp) :: acc - end handle Option => acc + end handle Option => elapsed_time acc in String.concat(List.rev (loop acc)) before TextIO.closeIn inp diff --git a/worker.sml b/worker.sml index 4b39db4..9152a67 100644 --- a/worker.sml +++ b/worker.sml @@ -252,7 +252,6 @@ fun upload id f = local val resume_file = "resume" val time_options = String.concat["--format='%e %M' --output='",timing_file,"'"] - val max_dir_length = 50 fun pad dir = let val z = String.size dir