                  (scheduler-complete! job-ref)))
              (recur))
 
-           (if (= (:in-progress (scheduler-stats))
-                  0)
-             (do
-               (info "Done!" (scheduler-stats))
-               (mount/stop)))
            ))))
 
     )

      (go
       (loop []
         (debug "Stats" (scheduler-stats))
         (if-let [job-ref (scheduler-take! 60000 nil)]
           ;; normal batches won't be nil
           ;; only get nil when no more jobs are added to the queue for a period of time
           (do
             (try
               (let [job (deref job-ref)]
                 (try
                   (run-index-batch db release-id job)
                   (scheduler-complete! job-ref)
                   (debug "Indexed" (or (meta job) :no_metadata))
                   (catch Exception e
                     (warn "Failed to index and scheduled to retry" (or (meta job) :no_metadata))
                     (scheduler-retry! job-ref) ; retried items are added at the end of the queue
                     )))
               (catch java.io.IOException e

      (let [db (d/db datomic-conn)]
        (do
          (run db)
          (schedule-jobs-all db)
          (connect-snapshot-repository repository-name)
          (scheduler-put! (with-meta {} {:action "snapshot"
                                         :index index-id
                                         :repository repository-name}))))

      ))
  )
