Skip to content
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

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

kddnewton
Copy link
Contributor

No description provided.

@kddnewton kddnewton force-pushed the handle-rate-limit branch 2 times, most recently from 2a2f2aa to 1756592 Compare May 21, 2024 18:27
Copy link
Member

@kmcphillips kmcphillips left a 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.


slack_response!(response)
end
while response.is_a?(Net::HTTPTooManyRequests) && attempts < 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 for a max attempts

Copy link
Member

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)

slack_response!(response)
end
while response.is_a?(Net::HTTPTooManyRequests) && attempts < 5
sleep(Integer(response["Retry-After"]))
Copy link
Member

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))

lib/smart_todo/slack_client.rb Show resolved Hide resolved
@kddnewton kddnewton force-pushed the handle-rate-limit branch 2 times, most recently from b5c4b16 to 2138a9f Compare June 26, 2024 20:19
Copy link
Member

@kmcphillips kmcphillips left a 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!

@kddnewton kddnewton merged commit ac00264 into main Jun 26, 2024
7 checks passed
@kddnewton kddnewton deleted the handle-rate-limit branch June 26, 2024 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants