How best to handle rate limiting/throttling

336 views
Skip to first unread message

James McKinney

unread,
Sep 28, 2013, 5:19:33 PM9/28/13
to typh...@googlegroups.com
I search this group and the issue queue, but I could not find a discussion.

Let's say I queue a bunch of requests to an API and then run the queue. At some point, I hit the rate limit and the server no longer responds with a 200 HTTP code. I would like to be able to have Typhoeus stop sending requests after it receives that first bad response. What is the best way to do it? Raising an exception inside a request's #on_complete when a rate limit is exceeded does the trick. Curious to hear if anyone has considered other alternatives. The following gist has sample code using plain Typhoeus and Typhoeus with Faraday.


Thanks,

James

Hans Hasselberg

unread,
Sep 28, 2013, 6:12:14 PM9/28/13
to typh...@googlegroups.com
Hi James,

you can use hydra.abort: http://rubydoc.info/github/typhoeus/typhoeus/Typhoeus/Hydra/Queueable#abort-instance_method. This will clear the queued instances and won't execute any subsequent requests.


--
You received this message because you are subscribed to the Google Groups "Typhoeus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to typhoeus+u...@googlegroups.com.
To post to this group, send email to typh...@googlegroups.com.
Visit this group at http://groups.google.com/group/typhoeus.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages