jegfish/goroyale

Ratelimit handling

Closed this issue · 1 comments

New/improved ratelimit handling besides an error message now implemented. It's still up to the user what to do with it but it's easier to handle. Here's a quick example:

switch e := err.(type) {
case goroyale.RatelimitError:
	// RatelimitError.RetryAfter is a time.Duration to wait before sending another request to the API.
	time.Sleep(e.RetryAfter)
}

More pressing issues

  • If multiple goroutines are running requests you can run into 429s. Ideas to fix:
    • Have rate limit remaining be a channel requests draw from and if there's nothing in the channel the request doesn't run. Problem with this is x-ratelimit-limit is not guaranteed to stay at 5 and the channel buffer size will probably need to be manually updated.

Some ideas for how to improve this in the future

  • Queue up requests and do something such as:
    • Still tell the user the ratelimit happened
    • Silently continue
    • Threshold of queued requests before flipping out

If anyone decides to use this lib I'd love to have some input on this.

Rate limit handling is now done through channels. The requests are essentially queued up as they wait for a request to be inserted into the channel.

Only possible changes I may make in the future is keeping track of X-Ratelimit-Remaining to insert multiple requests into the channel at once. For now one request is inserted at a time if X-Ratelimit-Remaining is greater than 0.