Created
September 24, 2013 14:48
-
-
Save fanatoly/6685873 to your computer and use it in GitHub Desktop.
tailrec
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
@tailrec | |
def fetchWithRetries(retries: Int): MultiFetchResponse = { | |
val resultMaybe = catching(classOf[IOException]) either { | |
simpleConsumer.multifetch(fetches : _*) | |
} | |
resultMaybe match{ | |
case Left(e) => | |
if(retries > 0) { | |
info("Unable to complete multifetch. Sleeping for %dms".format(config.fetcherBackoffMs), e) | |
Utils.swallow(logger.info, Thread.sleep(config.fetcherBackoffMs)) | |
fetchWithRetries(retries - 1) | |
} else { | |
throw e | |
} | |
case Right(result) => result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment