From b1214303db93dc96c06e4a06991b5c0fc7c030ba Mon Sep 17 00:00:00 2001 From: Uday Verma Date: Sat, 17 May 2014 22:34:22 -0500 Subject: [PATCH] Fix refresh issues on client side, add verbose to mv command to see why files are not being staged --- src-cljs/dakait/start.cljs | 9 +++++++-- src-cljs/dakait/util.cljs | 12 +++++++++++- src/dakait/staging.clj | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src-cljs/dakait/start.cljs b/src-cljs/dakait/start.cljs index dae09d1..330c50a 100644 --- a/src-cljs/dakait/start.cljs +++ b/src-cljs/dakait/start.cljs @@ -129,18 +129,22 @@ (def path-refresh-timeout (atom nil)) (def path-refresh-was-canceled (atom false)) +(def path-refresh-active-path (atom nil)) (defn path-refresh "Continously query the given path at regular intervals, should be cancellable" [path f] (let [to (js/setTimeout (fn [] - (log "Refreshing path...") (get-file-listing path (fn [list] - (when-not @path-refresh-was-canceled + ;; Make sure this response is for our currently active path + ;; and not a stale one + (when (and (not @path-refresh-was-canceled) + (= path @path-refresh-active-path)) (f list) (path-refresh path f))))) 2000)] + (reset! path-refresh-active-path path) (reset! path-refresh-was-canceled false) (reset! path-refresh-timeout to))) @@ -148,6 +152,7 @@ "Cancel an active path refresh loop" [] (when @path-refresh-timeout + (log "Clearing timeout: " @path-refresh-timeout) (js/clearTimeout @path-refresh-timeout) (reset! path-refresh-timeout nil) (reset! path-refresh-was-canceled true) diff --git a/src-cljs/dakait/util.cljs b/src-cljs/dakait/util.cljs index 94b8dde..4d2cefe 100644 --- a/src-cljs/dakait/util.cljs +++ b/src-cljs/dakait/util.cljs @@ -14,6 +14,16 @@ fixedSize (if (< n 1000000) 0 1)] (apply str [(.toFixed size fixedSize) postfix]))) +(defn- sub-hour-format-date + [n] + (let [now (quot (.getTime (js/Date.)) 1000) + diffInSecs (- now n)] + (cond + (< diffInSecs 5) "Less than 5 seconds ago" + (< diffInSecs 10) "Less than 10 seconds ago" + (< diffInSecs 60) "Less than a minute ago" + :else (str (inc (quot diffInSecs 60)) " minutes ago")))) + (defn format-date "Given a time stamp in seconds since epoch, returns a nicely formated time" [n] @@ -22,7 +32,7 @@ diffInSecs (quot (- now dt) 1000) diffInHours (quot diffInSecs 3600)] (cond - (< diffInHours 1) "Less than an hour ago" + (< diffInHours 1) (sub-hour-format-date n) (< diffInHours 2) "An hour ago" (< diffInHours 24) (str diffInHours " hours ago") (< diffInHours 48) "A day ago" diff --git a/src/dakait/staging.clj b/src/dakait/staging.clj index 0a2944f..3932f10 100644 --- a/src/dakait/staging.clj +++ b/src/dakait/staging.clj @@ -52,7 +52,7 @@ (.mkdirs (io/file dest)) (with-programs [mv] (info "Moving " src " -> " dest) - (mv src dest))) + (mv src dest {:verbose true}))) (defn stage-file "Helps stage the file, triggers download of the file to the staged configuration area, once the