     [core :as core]
     [util :refer [rfc2616-time str-stacktrace]]]
    [clojure.tools.logging :refer [info warn error]]
+   [slingshot.slingshot :refer [try+ throw+]]
    [environ.core :refer [env]]
    [clojure.string :refer [split]]
    [overtone.at-at :as at-at]))

      (error (str-stacktrace e)))))

(defn schedule
  [env & [action interval]]
  (let [pool (get-pool env)]
    (at-at/stop-and-reset-pool! pool :strategy :kill)
    (if (= action "stop")
      {:message "Succefully stopped the shuppet scheduler"}
      (let [interval (Integer/parseInt (or interval (env :service-scheduler-interval)))]
        (at-at/every (* interval 60 1000)
                     #(configure-apps env)
                     pool
                     :desc (rfc2616-time))
        {:message
         (str "Succesfully started the shuppet scheduler. The scheduler will run in every "
              interval " minutes.") }))))

(defn get-schedule
  [env]

  []
  (when-not (= (env :environment-name) "local") ;dont want the auto scheduler for our test envs
    (doseq [environment environments]
      (at-at/after (* (Integer/parseInt
                       (or (env (keyword (str "service-scheduler-delay-" environment))) "1"))
                      60 1000)
                   #(schedule environment)
                   (get-pool environment)
