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

Respect the Retry-After header #225

Merged
merged 11 commits into from
Oct 25, 2023
Merged

Respect the Retry-After header #225

merged 11 commits into from
Oct 25, 2023

Conversation

SmittieC
Copy link
Contributor

  • The DET will now sleep for the amount of seconds specified by the Retry-After header when it receives a 429 status from HQ.
  • Increased the default page size that UCR's will be exported with.
  • Changed the way we set the default page size.

HQ PR to return the Retry-After header

@SmittieC SmittieC requested review from snopoke and Charl1996 October 20, 2023 07:58
Copy link
Contributor

@snopoke snopoke left a 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

Copy link
Contributor

@zandre-eng zandre-eng left a 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.

commcare_export/commcare_minilinq.py Outdated Show resolved Hide resolved
commcare_export/commcare_minilinq.py Show resolved Hide resolved
@SmittieC SmittieC requested a review from snopoke October 23, 2023 10:13
@SmittieC
Copy link
Contributor Author

@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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@SmittieC SmittieC Oct 24, 2023

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@snopoke
Copy link
Contributor

snopoke commented Oct 24, 2023

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")
Copy link
Contributor Author

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?

@SmittieC SmittieC merged commit 4a811e6 into master Oct 25, 2023
5 checks passed
@SmittieC SmittieC deleted the cs/improve_retries branch October 25, 2023 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants