-
Notifications
You must be signed in to change notification settings - Fork 68
Automatically retry when rate limit is reached #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, we would like this feature to be implemented with the same features here. I think it's OK to start simple, but please design in a way that would allow upgrades. For example, to enable, we should pass in an object that allows us to configure the settings.
Thanks for starting this off!
lib/Client.php
Outdated
* | ||
* @return Response object | ||
*/ | ||
public function makeRequest($method, $url, $body = null, $headers = null) | ||
public function makeRequest($method, $url, $body = null, $headers = null, $retryOnLimit = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, this should be set to null to so we don't have a breaking change.
I don't believe handling other error is a good idea. it should be handled by the user. |
Hi @budirec, Could you please update the tests? https://travis-ci.org/sendgrid/php-http-client/jobs/270245199#L292 Thanks! |
|
||
if ($statusCode == 429 && $retryOnLimit) { | ||
$headers = $response->headers(true); | ||
$sleepDurations = $headers['X-Ratelimit-Reset'] - time(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain the idea behind this algorithm.
I want to make sure we don't overload our servers when something has gone wrong. I was hoping for a backoff strategy that eventually fails after a certain period of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every request we made to sendgrid will have X-Ratelimit-Reset in the header, where it tell us when the rate limit is reset in sendgrid.
So when ever we have error 429(rate limit reached) we use X-Ratelimit-Reset to determine how long the script need to wait before make another call to sendgrid.
This way we don't use a random time or predefined time.
Automatically retry when rate limit is reached
No description provided.