Throttle requests to mitigate RateLimitExceededExceptions#2145
Throttle requests to mitigate RateLimitExceededExceptions#2145EnricoMi merged 16 commits intoPyGithub:mainfrom
Conversation
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #2145 +/- ##
==========================================
- Coverage 98.36% 98.36% -0.01%
==========================================
Files 132 132
Lines 13280 13313 +33
==========================================
+ Hits 13063 13095 +32
- Misses 217 218 +1
☔ View full report in Codecov by Sentry. |
20eb0e8 to
aaad2dc
Compare
ce87a2c to
1868f80
Compare
abe0438 to
edf9ef9
Compare
|
@sfdye @s-t-e-v-e-n-k rebased and conflicts resolved, check it while it's hot! |
edf9ef9 to
35274c8
Compare
51cfbda to
d5c8fac
Compare
d5c8fac to
a03bc58
Compare
tests/Framework.pyi
Outdated
| # this file is needed so that tox -e lint does not complain about: | ||
| # tests/Requester.py:63: error: Incompatible types in assignment (expression has type "float", base class "BasicTestCase" defined the type as "None") | ||
| # tests/Requester.py:64: error: Incompatible types in assignment (expression has type "float", base class "BasicTestCase" defined the type as "None") |
There was a problem hiding this comment.
You can't fix this in BasicTestCase?
There was a problem hiding this comment.
Let me try to rework this.
There was a problem hiding this comment.
Moved into the .py file.
|
Tested this branch in https://github.com/EnricoMi/publish-unit-test-result-action/actions/runs/5271056850/jobs/9531604524#step:5:586 |
7a6997a to
cd3d699
Compare
cd3d699 to
ce52876
Compare
410f27f to
caff057
Compare
This introduces a throttling of requests to the Github REST API (1s for writes, 0.25s for reads, configurable) to mitigate secondary rate limit errors and comply with Github's best practices: https://docs.github.com/en/rest/guides/best-practices-for-integrators?apiVersion=2022-11-28#dealing-with-secondary-rate-limits
It defines a minimum time span between consecutive requests to the GitHub API, both caused by user code calling into the PyGithub API and called by PyGithub internally (e.g. user code iterating over a paginated list). This is achieved by hooking into the lowest possible method that is used to send all requests to GitHub API:
Requester.__requestRaw.For each verb the timestamp of the last request (when
__requestRawreturned) is recorded and used before the next request to compute the time that has to be waited before the request is issued. It then calls intotime.sleep()to respect the minimum time span.It distinguishes between the time between any request and the time between writes. GitHub expects at least one second between writing requests (e.g.
POST): https://docs.github.com/en/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limitsThis code is being used in EnricoMi/publish-unit-test-result-action and runs thousands of times each day.
Here is an example log:
This fixes #1989.