                           (future (with-error-delivery error
                                     (jetty/run-jetty app jetty))))
           db-gc         (do
-                          (log/info (format "Starting database compactor (%d minute interval)" db-gc-minutes))
+                          (log/info (format "Starting database sweeper (%d minute interval)" db-gc-minutes))
                           (future (with-error-delivery error
-                                    (db-compactor db mq-addr mq-endpoint db-gc-minutes node-ttl-days))))]
+                                    (sweep-database! db db-gc-minutes node-ttl-days))))]
 
       ;; Start debug REPL if necessary
       (let [{:keys [enabled type host port] :or {type "nrepl" host "localhost"}} (:repl config)]

                      :subprotocol "hsqldb"
                      :subname     (format "file:%s;hsqldb.tx=mvcc;sql.syntax_pgs=true" (file vardir "db"))}
        default-opts {:gc-interval 60
                      :node-ttl-days nil}
        db           (merge default-opts
                            (or database default-db))]
    (assoc config :database db)))

   (with-open [conn (mq/connect! mq)]
     (command/process-commands! conn mq-endpoint discard-dir {:db db}))))

(defn sweep-database!
  "Sweep the indicated database every `interval` minutes.

  This function doesn't terminate. If we encounter an exception during
  compaction, the operation will be retried after `interval` millis.

  This function will perform database garbage collection, and will also
  deactivate nodes more stale than `node-ttl-days`"
  [db interval node-ttl-days]
  (let [sleep #(Thread/sleep (* 60 1000 interval))]
    (pl-utils/keep-going
     (fn [exception]
       (log/error exception "Error during database sweep")
       (sleep))

     (pl-utils/demarcate
      "database garbage collection"
      (with-transacted-connection db
        (scf-store/garbage-collect!)))

     (when (pos? node-ttl-days)
       (pl-utils/demarcate
        (format "sweep of stale nodes (%s day threshold)" node-ttl-days)
        (with-transacted-connection db
          (doseq [node (scf-store/stale-nodes (time/ago (time/days node-ttl-days)))]
            (send-command! "deactivate node" 1 node)))))

     (sleep))))

