Created
April 30, 2012 23:15
-
-
Save aphyr/2563560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn send-event | |
"Send an event over client." | |
[^RiemannClient client event] | |
(with-io-retry client | |
(let [e (.event client)] | |
(when-let [h (:host event)] (.host e h)) | |
(when-let [s (:service event)] (.service e s)) | |
(when-let [s (:state event)] (.state e s)) | |
(when-let [d (:description event)] (.description e d)) | |
(when-let [m (:metric event)] (.metric e (float m))) | |
(when-let [t (:tags event)] (.tags e t)) | |
(when-let [t (:time event)] (.time e (int t))) | |
(when-let [t (:ttl event)] (.time e (float t))) | |
(.send e)))) | |
(defmacro with-io-retry | |
"Calls body, retries one IOException by reconnecting client, raises if that | |
fails too." | |
[^RiemannClient client & body] | |
`(try | |
(do ~@body) | |
(catch IOException e# | |
(warn "Client recovering from IO exception") | |
(reconnect-client ~client) | |
(do ~@body)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment