Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; get data from archai DB
  2. ;; put data to elastic DB
  3. ;; it is slow so i have to do async
  4.  
  5. ;; issue
  6. ;; i have to start sync BAR when FOO finished
  7. ;; How?
  8.  
  9. (defn archai->elastic-refresh []
  10.   (let [epochs (archai/generate-epochs epochs-from-now)
  11.         in-archai (chan 100)
  12.         out-elastic (chan 100)
  13.         archai->elastic (fn [input out*]
  14.                           ;; todo
  15.                           ;; here convert archai into elastic data in #()
  16.                           (archai/fetch-epoch #(>!! out-elastic %) input)
  17.                           (close! out*))
  18.         worker (dotimes [_ workers-elastic]
  19.                  (go-loop []
  20.                    (let [input (<! out-elastic)]
  21.                      (when-not (nil? input)
  22.                        (<! (thread
  23.                              (try
  24.                                (elastic/archai->push input)
  25.                                (catch Throwable ex
  26.                                  (l/error ex)))))
  27.                        (recur)))))]
  28.     (pipeline-async workers-archai out-elastic archai->elastic in-archai)
  29.  
  30.     (doseq [epoch epochs]
  31.       (>!! in-archai {:url (archai/make-url {:stream "FOO"
  32.                                              :epoch epoch})}))
  33.     ;; todo
  34.     ;; be sure first one end
  35.  
  36.     #_(doseq [epoch epochs]
  37.         (>!! in-archai {:url (archai/make-url {:stream "BAR"
  38.                                                :epoch epoch})}))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement