-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle rate limiting by sleeping required amount #80
Conversation
2a2f2aa
to
1756592
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Thanks for just finding and fixing.
lib/smart_todo/slack_client.rb
Outdated
|
||
slack_response!(response) | ||
end | ||
while response.is_a?(Net::HTTPTooManyRequests) && attempts < 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 for a max attempts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'd put this in a const or def dispatch(request, max_attempts=5)
lib/smart_todo/slack_client.rb
Outdated
slack_response!(response) | ||
end | ||
while response.is_a?(Net::HTTPTooManyRequests) && attempts < 5 | ||
sleep(Integer(response["Retry-After"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be real safe, and guard against some eccentric response or parsed value, you could do:
sleep(min(Integer(response["Retry-After"]), SOME_SAFE_MAXIMUM_SECONDS))
b5c4b16
to
2138a9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better with tests!
2138a9f
to
c01327f
Compare
No description provided.