Skip to content

Commit

Permalink
Fix refresh issues on client side, add verbose to mv command to see w…
Browse files Browse the repository at this point in the history
…hy files are not being staged
  • Loading branch information
verma committed May 18, 2014
1 parent a4d7974 commit b121430
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src-cljs/dakait/start.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,30 @@

(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)))

(defn cancel-path-refresh
"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)
Expand Down
12 changes: 11 additions & 1 deletion src-cljs/dakait/util.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/dakait/staging.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b121430

Please sign in to comment.