-
Notifications
You must be signed in to change notification settings - Fork 18
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
Respect the Retry-After header #225
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.
You should be able to use the backoff decorator to implement the 'retry-after' rather than doing it separately: https://github.com/litl/backoff#backoffruntime
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.
Looks good, just a few non-blocking comments.
@snopoke are you happy with this PR? |
retry_after = response.headers.get("Retry-After", 0.0) | ||
retry_after = ceil(float(retry_after)) | ||
logger.warning(f"Sleeping for {retry_after} seconds") | ||
time.sleep(retry_after) |
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.
this isn't what I had in mind but I guess it works.
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.
Another way is to use the wait_gen
parameter to give it the time to wait for, but it would need to be context aware. Currently the decorator is not. Do do this, we can wrap this whole get method along with the decorator inside an instance method. That way we can get a wait_gen
generator that is able to determine how long to wait for, depending on the Retry-After value.
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.
Yea, I was thinking of something like that. It might get ugly though. We'd also need to modify the response.raise_for_status()
call so that we don't do double backoff.
I'm fine with this for now if you would rather try the other approach later.
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.
Thoughts on this approach rather? 388a507
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.
Looks good to me
A unit test would be great |
@@ -291,6 +291,26 @@ def test_message_log(self): | |||
[1, 2, 3] | |||
) | |||
|
|||
@patch("commcare_export.commcare_hq_client.CommCareHqClient.session") |
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.
Not sure what else we'd want to test?
Retry-After
header when it receives a 429 status from HQ.HQ PR to return the
Retry-After
header