Last active
June 20, 2016 17:47
-
-
Save andypern/42a4bd8c0fef661024478b46c842d4a1 to your computer and use it in GitHub Desktop.
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
max_retries = 5 | |
try: | |
do_stuff(objKey) | |
except (somerror) as e: | |
logger.error('got a timeout for %s -> %s', objKey, e) | |
# | |
#retry until we either succeed, or reach max_retries | |
# | |
for attempt in range(max_retries): | |
# | |
#exponential backoff | |
# | |
print "sleeping for %s secs before retry" %(2 ** attempt) | |
time.sleep(2 ** attempt) | |
try: | |
do_stuff(objKey) | |
print "shit worked" | |
break | |
except (somerror) as e: | |
if attempt < (max_retries - 1): | |
logger.error('attempt %s for %s failed with %s, %s remaining', attempt + 1, objKey,e,max_retries - attempt) | |
continue | |
else: | |
logger.error('All %s attempts for %s failed, aborting this file',max_retries,objKey) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment