 
 
 (defn manage-filesystem*
-  [id {:keys [fsid sleep-between-sync]}]
+  [rmq-settings id {:keys [fsid sleep-between-sync]}]
   (let [qname (rk/routing-key-string-from-map {:id id :filesystem fsid :command "*"})
         get-num-messages (fn []
                            (num-messages-from-queue-state



(defn start-synchronization
  [id filesystem]
  (let [conn (rmq/connect)
        ch (lch/open conn)]
    (mqhelper/initialize-rabbitmq-structures
     ch "listdir" id filesystem)

    (wait-idle)
    (while true
      (logging/info "starting synchronization of" qname)
      (start-synchronization rmq-settings id fsid)
      (Thread/sleep 10000)
      (wait-idle)
      (logging/info "synchronization of" qname "finished. restarting in" sleep-between-sync "seconds")
      (Thread/sleep (* sleep-between-sync 1000)))))

(defn manage-filesystem
  [rmq-settings id fsextra]
  (try-try-again {:sleep (* 60 1000)
                  :tries :unlimited
                  :error-hook (fn [e] (logging/error "error in manage-filesystem" (:fsid fsextra) e))}
                 #(manage-filesystem* rmq-settings id fsextra)))

(defrecord ManageService [rmq-settings rmq-prefix filesystems]
  worker/Service
  (start [this]
    (doseq [fs filesystems]
      (future (manage-filesystem rmq-settings rmq-prefix fs)))))

(defn http-connect!
  [{:keys [api-endpoint username password]}]
