cscheid / rgithub

R bindings for the github API
MIT License
70 stars 31 forks source link

Managing rate limits? #41

Closed aronlindberg closed 9 years ago

aronlindberg commented 9 years ago

It would be helpful to have automatic management of rate limits.

I don't know how to implement this across the board, but I have some ideas for a "manual" solution. $x-ratelimit-remaining tracks how many requests you have left and $x-ratelimit-reset is a timestamp formatted as seconds-since-the-epoch. I suppose that if the query is wrapped in a loop one can check when $x-ratelimit-remaining is approaching zero, and then simply implement Sys.sleep() until the rate limit has been reset, and then resume the looping of your queries.

For example:

if (downloaded_api_response$headers$x-ratelimit-remaining< 5) Sys.sleep(as.integer(files$headers$x-ratelimit-reset)-as.POSIXct( Sys.time() ) %>% as.integer()) else do stuff

What do you think of this (as a manual solution)?

cscheid commented 9 years ago

I don't think it's the role of rgithub to perform rate-limiting. But one thing it could do is simply refuse to issue the request (and throw an exception, for example) if we've used our rate limits.

So your solution seems to be just fine, but I don't think the current state of rgithub is bad enough for it to be an issue.