Skip to content

Instantly share code, notes, and snippets.

@lyuboraykov
Created August 7, 2014 13:18
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 lyuboraykov/249b34136b18fd3aac4f to your computer and use it in GitHub Desktop.
Save lyuboraykov/249b34136b18fd3aac4f to your computer and use it in GitHub Desktop.
Retryable logic in groovy
def retry(lambda, retries) {
for (def i = 0; i < retries; i++) {
try {
//better replace with logger
// println "Retrying: ${i + 1} of $retries"
lambda()
break
} catch (e) {
if (i == retries - 1) {
throw new Exception('Retrying failed', e)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment