Comments (11)
Whoops, should have dug into the code:
65da365#diff-00b86054467328d3459932d83679b66bR49
from desk.
Ah, great. Thanks for updating. Sorry that I hadn't had a chance to check it out yet.
from desk.
Actually - I had it opposite! config.use_max_requests = true
enforces the maximum requests in the Desk gem; I thought it did the opposite. So reopening as I think this is an issue in the default max requests retry functionality...
from desk.
Hmm, maybe there isn't any back-off-and-retry-if-too-many-requests code. It would be cool to add support for this. What do you think Chris?
from desk.
Yeah, that would be great to have; feel free to give it a shot.
from desk.
Okay giving this a go now...
from desk.
Right I have done some digging...
The existing gem has:
when 420
raise Desk::EnhanceYourCalm.new(error_message(env), env[:response_headers])
Which is confusing, because 420 is not listed as a Desk.com response code:
http://dev.desk.com/API/using-the-api/#status-codes
Also I don't understand this:
class EnhanceYourCalm < Error
# The number of seconds your application should wait before requesting date from the Search API again
#
# @see http://dev.desk.com/pages/rate-limiting
def retry_after
@http_headers.values_at('retry-after', 'Retry-After').detect {|value| value }.to_i
end
end
Again, this Retry-After
header is not mentioned anywhere in the Desk.com documentation...
Is this all an artifact from an earlier version of Desk.com, or maybe a copy-paste error from an old Twitter API client?
Another thing:
def ratelimit_limit
@http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect {|value| value }.to_i
end
def ratelimit_remaining
@http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect {|value| value }.to_i
end
I think this is a copy-paste error - last strings should be 'x-ratelimit-remaining', 'X-RateLimit-Remaining'.
Confusingly, you do have an exception TooManyRequests
:
# Raised when Desk max_requests is reached and use_max_requests is set to true
class TooManyRequests < StandardError; end
but this is an internal error, thrown when the client determines that it thinks Desk.com itself would start throwing TooManyRequests errors (which are uncaught).
As an internal error, TooManyRequests inherits from StandardError
, so does not have access to the very helpful ratelimit_...
arguments.
@chriswarren what do you suggest we do? My suggestion would be:
- Fix the mistakes in ratelimit_remaining
- Remove EnhanceYourCalm and stop catching 420
- Rename the current TooManyRequests to TooManyRequestsClient
- Create a new TooManyRequestsApi and throw it on 429
Please advise...
from desk.
It looks like the Zendesk API does support Retry-After
, but not the Desk.com API:
https://support.zendesk.com/entries/35459738-Best-practices-for-avoiding-rate-limiting
from desk.
Sorry I'm late to the party. Some of the code is a hold over from the Desk.com (formerly Assistly) API v1 and a little bit is a hold over from the Twitter gem. The EnhanceYourCalm comes from that Twitter holdover (from the pre-v1.1 API). Since Desk is now using the 429 response code (as indicated on the page you linked to above), it may be as simple as changing the "when 420" line to "when 429".
I know the code used to work and still passes the tests so it's likely just that they changed status response codes.
from desk.
Also, if you look here: http://dev.desk.com/API/using-the-api/#rate-limits
It looks like, instead of using the 'Retry-after' header, we should now be using the 'X-Rate-Limit-Reset' header.
And for the ratelimit_limit and ratelimit_remaining functions we should have a dash between "rate" and "limit" since they're:
X-Rate-Limit-Limit
X-Rate-Limit-Remaining
Those 2 changes and the one above should resolve the problem. @alexanderdean if you want to make the changes and test them then that would be awesome.
from desk.
Hi @colinc - it sounds like we're on the same page. I will put something together per the above...
from desk.
Related Issues (20)
- Copy-paste errors in ratelimit_remaining
- Faraday parsing errors even after #31 HOT 12
- Please update faraday dependency / conflicts with google oauth2 HOT 1
- gem "hashie" issue HOT 7
- Search case by order_no HOT 7
- collections only respond to each instead of all of Enumerable HOT 4
- Raise Desk-namespaced exceptions for other non-200 responses
- 422 error response not parsed correctly HOT 5
- Faraday::ParsingError: 757: unexpected token at 'Too Many Requests' HOT 1
- Desk.com gem ignores client config? HOT 2
- Desk.delete_case is not working HOT 3
- Logger does not log request and response body
- Document how to log request and response
- RuntimeError: missing dependency for FaradayMiddleware::Deashify: undefined method `type' for class `Hashie::Mash' HOT 9
- Incorrect from/reply_to address
- Configuration Issue
- Desk.insights_meta produces a 404 HOT 2
- Problem with the Thread.current in the Configuration HOT 1
- Bug when creating articles HOT 1
- Hashie fixed version giving conflicts HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from desk.