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

feat: add exponential backoff #13

Merged
merged 2 commits into from
May 17, 2024
Merged

feat: add exponential backoff #13

merged 2 commits into from
May 17, 2024

Conversation

EverVino
Copy link

Pull Request description

This PR aims to implement a exponential backoff. pymedx fetch data from a remote server (PubMed). This operation can fail for a myriad of reasons – network issues, server overload, brief disruptions in service, etc. If the application simply gives up after the first failure, it risks missing out on the opportunity to succeed in a subsequent attempt.
This is where retrying comes in as a basic yet crucial mechanism. So in other words If the first attempt did not succeed pymedx will wait for 2 seconds, if the second attempt fail pymedx will wait for 4 seconds and so on, the sequence in waiting times is 0 2 4 8 16 32 32 32 32 (seconds). Notice that is caped at 32 seconds

I added a jitter as well which is added to backoff_time and is a float number between 0 and 1. The addition of a random “jitter” avoids the scenario where many clients, following the same exponential backoff algorithm, retry simultaneously.

  • Constants added maxRetires = 10
  • New function wait_to_retry

Pull Request checklists

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more
    complexity.
  • New and old tests passed locally.

Additional information

Reviewer's checklist

Copy and paste this template for your review's note:

## Reviewer's Checklist

- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] I confirm that the issues mentioned were fixed/resolved .

@EverVino
Copy link
Author

@xmnlab ready for a review. This PR add a exponential backoff when request did not succeed

@xmnlab xmnlab merged commit 42cf7c3 into main May 17, 2024
8 checks passed
@xmnlab xmnlab deleted the add-exponential-backoff branch May 17, 2024 20:34
Copy link

🎉 This PR is included in version 0.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants