-
-
Save khamidou/3e36ffdf36ab2d967771c74d79de85ca to your computer and use it in GitHub Desktop.
Exponential backoff with jitter in Ruby
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
# Exponential backoff in Ruby | |
begin | |
make_request | |
rescue RequestError => e | |
if retries <= max_retries | |
retries += 1 | |
sleep 2 ** retries + rand(20) | |
retry | |
else | |
raise "Timeout: #{e.message}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment