Skip to content

Instantly share code, notes, and snippets.

@aphyr
Created April 30, 2012 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aphyr/2563560 to your computer and use it in GitHub Desktop.
Save aphyr/2563560 to your computer and use it in GitHub Desktop.
(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