Skip to content

Instantly share code, notes, and snippets.

@fanatoly
Created September 24, 2013 14:48
Show Gist options
  • Save fanatoly/6685873 to your computer and use it in GitHub Desktop.
Save fanatoly/6685873 to your computer and use it in GitHub Desktop.
tailrec
@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