Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 138
fix bug rate_limit_details returned and a bug for intercom request header#578
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
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -72,11 +72,11 @@ def execute(target_base_url = nil, token:, read_timeout: 90, open_timeout: 30, a | ||||||||||
| parsed_body | ||||||||||
| rescue Intercom::RateLimitExceeded => e | ||||||||||
| if @handle_rate_limit | ||||||||||
| seconds_to_retry = (@rate_limit_details[:reset_at] - Time.now.utc).ceil | ||||||||||
| seconds_to_retry = ((@rate_limit_details[:reset_at] || Time.now.utc) - Time.now.utc).ceil | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, this line is basically implementing a default Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is a problem with the intercom server, or something like that, where this is not getting reset_at, we don't want to keep sleeping the application because we don't know if we are hitting the rate limit. If we hit the rate limit, the error will be raised where we will try to redo the call. If we hit it multiple times it will just "crash" and we will get a response error in the end user. But yeah...maybe I should convert | ||||||||||
| if (retries -= 1) < 0 | ||||||||||
| raise Intercom::RateLimitExceeded, 'Rate limit retries exceeded. Please examine current API Usage.' | ||||||||||
| else | ||||||||||
| sleep seconds_to_retry unless seconds_to_retry < 0 | ||||||||||
| sleep seconds_to_retry unless seconds_to_retry <= 0 | ||||||||||
| ||||||||||
| sleepseconds_to_retryunlessseconds_to_retry <= 0 | |
| sleepseconds_to_retryunlessseconds_to_retry.negative? |
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.
.negative? is (-1, -2, -3), we want to include (0, -1, -2, -3). :o
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.
My thinking was that the current <= implementation is just there to prevent an ArgumentError when we call sleep with a negative argument. Do we really want to protect against a 0 argument here?
My feeling is that changing this condition is not really relevant to the change we are looking to make in this PR so we might be best leaving this condition unchanged.
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.
Well if possible would optimise it a bit. I think if you want to sleep something for 0 seconds...its kinda off.
samrjenkinsJan 10, 2022 •
edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
If you're keen to make this change then perhaps this?
| sleepseconds_to_retryunlessseconds_to_retry <= 0 | |
| sleepseconds_to_retryifseconds_to_retry.positive? |
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.
Do you mean?
I think this is your intention from what I understand of the PR description