Created
July 20, 2015 17:52
-
-
Save cap10morgan/c022fda990b870005434 to your computer and use it in GitHub Desktop.
lazy-seq connect-to-broker
This file contains hidden or 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 connect-to-broker | |
([config] (connect-to-broker config 5)) | |
([config max-tries] | |
(first (drop-while nil? (connect-to-broker config max-tries 1)))) | |
([config max-tries attempt] | |
(if (<= attempt max-tries) | |
(try | |
[(rmq/connect config)] | |
(catch Throwable t | |
(log/warn "RabbitMQ not available:" (.getMessage t) "attempt:" attempt) | |
(lazy-seq | |
(Thread/sleep (* attempt 1000)) | |
(connect-to-broker config max-tries (inc attempt))))) | |
nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment