             [polismath.metrics :as met]
             [polismath.db :as db]
             [polismath.utils :refer :all]
+            [plumbing.core :as pc]
             [clojure.core.matrix.impl.ndarray]
             [clojure.core.async
              :as as

  "Returns a clojure that can be called in case there is an update error. The closure gives access to
  the queue so votes can be requeued"
  [queue conv-actor]
  (fn [vote-batches start-time opts update-error]
    (let [zid-str (str "zid=" (:zid @conv-actor))]
      (log/error "Failed conversation update for" zid-str)
      (.printStackTrace update-error)

(defn update-fn
  "This function is what actually gets sent to the conv-actor. In addition to the conversation and vote batches
  up in the channel, we also take an error-callback. Eventually we'll want to pass opts through here as well."
  [conv votes error-callback]
  (let [start-time (System/currentTimeMillis)]
    (try
      (let [updated-conv   (conv/conv-update conv votes)
            zid            (:zid updated-conv)
            finish-time    (System/currentTimeMillis)]
        (log/info "Finished computng conv-update for zid" zid "in" (- finish-time start-time) "ms")
