exception doesn't work, try another technique

This commit is contained in:
Yann Esposito 2015-03-18 18:16:31 +01:00
parent 9a72e63932
commit 4f429f5463
2 changed files with 11 additions and 5 deletions

View file

@ -1,4 +1,4 @@
(defproject bigbrother "0.1.2" (defproject bigbrother "0.1.3-SNAPSHOT"
:description "Periodically send metrics" :description "Periodically send metrics"
:url "http://github.com/yogsototh/bigbrother" :url "http://github.com/yogsototh/bigbrother"
:license {:name "MIT" :license {:name "MIT"

View file

@ -109,14 +109,20 @@ end
:state level :state level
:metric v})))) :metric v}))))
(defmacro with-timeout [millis & body]
`(let [future# (future ~@body)]
(try
(.get future# ~millis java.util.concurrent.TimeUnit/MILLISECONDS)
(catch java.util.concurrent.TimeoutException x#
(do
(future-cancel future#)
nil)))))
(defn send-to-riemann [m] (defn send-to-riemann [m]
(let [result-map (into @default-map m) (let [result-map (into @default-map m)
events (remove nil? (map to-riemann-event result-map))] events (remove nil? (map to-riemann-event result-map))]
(when @riemann-conn (when @riemann-conn
(try (with-timeout 1000 (r/send-events @riemann-conn events)))))
(r/send-events @riemann-conn events)
(catch Exception e
(log/error e))))))
(defn reset-accumulators! [] (defn reset-accumulators! []