             [puppetlabs.puppetdb.cheshire :as json]
             [me.raynes.fs :as fs]
             [clojure.java.io :as io]
-            [puppetlabs.puppetdb.utils :as utils]
+            [puppetlabs.puppetdb.utils :as utils :refer [println-err]]
             [puppetlabs.kitchensink.core :as kitchensink]
             [clj-time.core :as time]
             [puppetlabs.puppetdb.client :as client]

           :catalog catalog
           :factset factset)))

(defn submit-n-messages
  "Given a list of host maps, send `num-messages` to each host.  The function
   is recursive to accumulate possible catalog mutations (i.e. changing a previously
   mutated catalog as opposed to different mutations of the same catalog)."

          (<! message-timeout)
          (recur))))))

(defn random-hosts
  [n pdb-host catalogs reports facts]
  (let [random-entity (fn [host entities]
                        (some-> entities
                                rand-nth
                                (assoc "certname" host)))]
    (for [i (range n)]
      (let [host (str "host-" i)]
        {:host host
         :catalog (when-let [cat (random-entity host catalogs)]
                    (update cat "resources"
                            (partial map #(update % "tags"
                                                  conj
                                                  pdb-host))))
         :report (random-entity host reports)
         :factset (random-entity host facts)}))))

(defn populate-queue
  "Fills queue with host entries.  Stops if mq is closed."
  [mq numhosts run-interval pdb-host catalogs reports facts]
  (println-err (trs "Populating queue in the background"))
  (doseq [host (random-hosts numhosts pdb-host catalogs reports facts)
          :while (>!! mq (assoc host :lastrun
                                (rand-lastrun run-interval)))]
    true)
  (println-err (trs "Finished populating queue")))

(defn benchmark-main
  [& args]
  (let [{:keys [config rand-perc numhosts nummsgs threads] :as options} (validate-cli! args)
