Skip to content
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

Added optional rate limit handling. #155

Merged
merged 8 commits into from
Dec 21, 2017
Merged

Added optional rate limit handling. #155

merged 8 commits into from
Dec 21, 2017

Conversation

andy-trimble
Copy link
Contributor

This addresses issue #100.

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Oct 12, 2017
@SendGridDX
Copy link

SendGridDX commented Oct 12, 2017

CLA assistant check
All committers have signed the CLA.

@thinkingserious thinkingserious added difficulty: hard fix is hard in difficulty hacktoberfest labels Oct 12, 2017
@thinkingserious
Copy link
Contributor

Sorry for the inconvenience @andy-trimble, but we need this CLA signed also. Unfortunately, the CLA does not propagate across all repos.

Also, could you please take care of the conflict? Thanks!

@tariq1890
Copy link
Contributor

I thought I'll chime in here since I had volunteered to fix issue #100. These are the issues that I'd think you need to fix

i. You are using a constant retry time. I believe the expected way is to use you read the Rate limit Reset header to get the sleep time.
ii. I strongly think the method should be defined at the rest library level rather than here. Which is why I waiting for #94 to get closed out.
iii. Also, as per previous discussions, it was decided that users would be given an option to use this retry on limit feature. Shouldn't we be using a boolean flag for this?

@andy-trimble
Copy link
Contributor Author

@tariq1890 Thanks for the comment.

  1. Good point. That should be an easy fix.
  2. I'd be interested in why you think it belongs in the rest library? Especially if we use the "X-RateLimit-Remaining" it's a SendGrid specific solution.
  3. This implementation is optional. It is a separate function call. API() is synchronous, and Request() is asynchronous with a retry on rate limit.

@tariq1890
Copy link
Contributor

Hi @andy-trimble

  1. The rest library I am referring to is the sendgrid/rest repo. I believe that is the repo used to construct requests and process responses. The retry-on-limit falls within that scope IMO. Since it is a sendgrid repo, this sendgrid-specific task is pertinent IMO.

3.As an outsider who would use the API, I don't find the fact that API would mean synchronous and Request() would mean async obvious. I believe a flag would be better for the sake of readability here. Third-pary users would find that more intuitive no?

@andy-trimble
Copy link
Contributor Author

@tariq1890

  1. That particular Rest library is a SendGrid library, but it is a generic rest client. We happen to use it internally for things that won't behave this way. This would be onerous for systems that have a different rate limiting schema, for example.

  2. I do agree that API() isn't a good function name 😄 . I didn't want to make that broad of a change (and thereby break backwards compatibility). I think it would fall to another issue to fix that. Do you have a suggestion for a function name aside from Request()?

  3. If it is desirable to actually have a blocking rate limit aware call, then I can definitely make a separate function for that. But I do believe the asynchronous, channel-based solution provides merit.

@tariq1890
Copy link
Contributor

  1. Gotcha. That makes sense.

  2. Can we consider adding this as an extra flag parameter to the method? The sendgrid-php repo that @thinkingserious referenced uses the flag iirc.

  3. I was just going to suggest that. Block until the response is 200 OK for retry-on-limit. Right your code only retries once getting a 429 response.

@andy-trimble
Copy link
Contributor Author

andy-trimble commented Oct 12, 2017

  1. I'm open to this implementation, but I prefer a clean, boolean-less interface. I wouldn't mind so much if this were, say, Python or PHP and we could specify a default value. But generally, the fewer function parameters, the better (and more readable). Additionally, altering the API() function breaks backwards compatibility, something I was trying to avoid.

  2. I'll add a blocking function.

@thinkingserious
Copy link
Contributor

@suchitparikh

@thinkingserious
Copy link
Contributor

@tariq1890, @andy-trimble,

Currently, @suchitparikh is working on refactoring this repo, per this issue. I encourage you to collaborate with him there.

With regards to the conversation in this thread:

  1. In the rest client, we are renaming API to Send and passing through to the API function to avoid the breaking change. But, in @suchitparikh's refactor we are brining that functionality into the library.

@thinkingserious thinkingserious merged commit fc52a74 into master Dec 21, 2017
@thinkingserious
Copy link
Contributor

Hello @andy-trimble,

Thanks again for the PR!

We appreciate your contribution and look forward to continued collaboration. Thanks!

Team SendGrid DX

@childish-sambino childish-sambino deleted the rate_limit branch January 28, 2020 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: hard fix is hard in difficulty status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants