gh icon indicating copy to clipboard operation
gh copied to clipboard

Rate limit helpers

Open hadley opened this issue 7 years ago • 2 comments

i.e. see how many requests you have left in the current period, and another function to automatically wait until you have another request

hadley avatar Jan 02 '18 13:01 hadley

Related to this, I think it would be helpful to have a simple .wait parameter to gh(), which specifies the wait period in seconds between API calls. This would allow the user to rely upon the .limit = Inf existing functionality without getting an error due to the API rate being exceeded. The point is to avoid the user to have to write their own loops using gh_next() etc.

E.g., avoid:

> moodle_commmits_12months = gh("GET /repos/:owner/:repo/commits", owner = "moodle", repo = "moodle", since = year_ago, .limit = Inf)
ℹ Running gh query, got 66600 records of about 77700Error in gh_process_response(raw) : 
GitHub API error (403): 403 Forbidden
Message: API rate limit exceeded for MY_IP. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
Read more at https://developer.github.com/v3/#rate-limiting

(Note there is a lack of newline here making the error message hard to read.)

By using something like:

moodle_commmits_12months = gh("GET /repos/:owner/:repo/commits", owner = "moodle", repo = "moodle", since = year_ago, .limit = Inf, .wait = 10)

Deleetdk avatar Mar 08 '20 20:03 Deleetdk

@Deleetdk I guess #113 will address that?

gaborcsardi avatar Nov 09 '20 11:11 gaborcsardi

We could also resolve this by switching to httr2, since that has a helpers (https://httr2.r-lib.org/reference/req_retry.html and https://httr2.r-lib.org/reference/req_throttle.html) built in.

hadley avatar Feb 06 '23 14:02 hadley