move actual view refresh processing to new fn to make testing easier

This commit is contained in:
Gered 2016-05-27 11:46:46 -04:00
parent c31a896bd0
commit 1c47d4ca67

View file

@ -243,16 +243,8 @@
[last-update min-refresh-interval]
(Thread/sleep (max 0 (- min-refresh-interval (- (System/currentTimeMillis) last-update)))))
(defn refresh-worker-thread
"Returns a refresh worker thread function. A 'refresh worker' continually waits for
refresh requests and when there is one, handles it by running the view, getting the view
data and then sending it out to all the view's subscribers. "
[]
(let [^ArrayBlockingQueue refresh-queue (:refresh-queue @view-system)]
(fn []
(try
(when-let [{:keys [namespace view-id parameters] :as view-sig} (.poll refresh-queue 60 TimeUnit/SECONDS)]
(trace "worker running refresh for" view-sig)
(defn do-view-refresh!
[{:keys [namespace view-id parameters] :as view-sig}]
(if (collect-stats?) (swap! statistics update-in [:refreshes] inc))
(try
(let [view (get-in @view-system [:views view-id])
@ -264,6 +256,18 @@
(swap! view-system assoc-in [:hashes view-sig] hdata)))
(catch Exception e
(error e "error refreshing:" namespace view-id parameters))))
(defn refresh-worker-thread
"Returns a refresh worker thread function. A 'refresh worker' continually waits for
refresh requests and when there is one, handles it by running the view, getting the view
data and then sending it out to all the view's subscribers. "
[]
(let [^ArrayBlockingQueue refresh-queue (:refresh-queue @view-system)]
(fn []
(try
(when-let [view-sig (.poll refresh-queue 60 TimeUnit/SECONDS)]
(trace "worker running refresh for" view-sig)
(do-view-refresh! view-sig))
(catch InterruptedException e))
(if-not (:stop-workers? @view-system)
(recur)