       (log/info starting-str)
       (log-cli-cmd options)
       (dry-mode-warn options)
-      (let [tpool (get-thread-pool options)
-            pstore (pstore/elasticsearch-path-store es-url options)
-            sort (get-sort-or-dummy-fn (:sort options))
-            processed-data (process-metrics tenant rollups paths cass-hosts
-                                            pstore options
-                                            remove-obsolete-metrics-processor
-                                            tpool)
-            obsolete-paths (->> processed-data
-                                (get-paths-from-paths-rollups (first rollups))
-                                (filter #(contains? @paths-info %))
-                                (sort)
-                                (doall))]
-        (swap! paths-info (fn [_] nil))
-        (process-paths tenant obsolete-paths pstore options
-                       remove-obsolete-paths-processor tpool)))
+      (cp/with-shutdown! [tpool (get-thread-pool options)]
+        (let [pstore (pstore/elasticsearch-path-store es-url options)
+              sort (get-sort-or-dummy-fn (:sort options))
+              processed-data (process-metrics tenant rollups paths cass-hosts
+                                              pstore options
+                                              remove-obsolete-metrics-processor
+                                              tpool)
+              obsolete-paths (->> processed-data
+                                  (get-paths-from-paths-rollups (first rollups))
+                                  (filter #(contains? @paths-info %))
+                                  (sort)
+                                  (doall))]
+          (swap! paths-info (fn [_] nil))
+          (process-paths tenant obsolete-paths pstore options
+                         remove-obsolete-paths-processor tpool))))
     (catch Exception e
       (clog/unhandled-error e))))
 

  (try
    (clog/disable-logging!)
    (set-inspecting-on!)
    (let [tpool (get-thread-pool options)
          mstore (mstore/cassandra-metric-store cass-hosts options)
          pstore (pstore/elasticsearch-path-store es-url options)
          sort (get-sort-or-dummy-fn (:sort options))
          obsolete-data (->> (get-paths pstore tenant paths
                                        (:exclude-paths options)
                                        (:sort options))
                             (filter-obsolete-metrics mstore tpool tenant

      (log/info starting-str)
      (log-cli-cmd options)
      (dry-mode-warn options)
      (cp/with-shutdown! [tpool (get-thread-pool options)]
        (let [pstore (pstore/elasticsearch-path-store es-url options)
              sort (get-sort-or-dummy-fn (:sort options))
              empty-paths (->> (tree-walker tenant paths pstore options
                                            empty-paths-finder tpool)
                               (sort))]
          (process-paths tenant empty-paths pstore options
                         remove-empty-paths-processor tpool))))
    (catch Exception e
      (clog/unhandled-error e))))

