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

Fix ratelimit timezone #362

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adabot/circuitpython_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def run_library_checks(validators, kw_args, error_depth):
break
except pygithub.RateLimitExceededException:
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
sleep_time = core_rate_limit_reset - datetime.datetime.now()
sleep_time = core_rate_limit_reset - datetime.datetime.utcnow()
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
time.sleep(sleep_time.seconds)
continue
Expand Down
5 changes: 5 additions & 0 deletions adabot/github_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def request(method, url, **kwargs):
logging.warning(
"GitHub API Rate Limit reached. Pausing until Rate Limit reset."
)
# This datetime.now() is correct, *because* `fromtimestamp` above
# converts the timestamp into local time, same as now(). This is
# different than the sites that use GH_INTERFACE.get_rate_limit, in
# which the rate limit is a UTC time, so it has to be compared to
# utcnow.
while datetime.datetime.now() < rate_limit_reset:
logging.warning("Rate Limit will reset at: %s", rate_limit_reset)
reset_diff = rate_limit_reset - datetime.datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion adabot/lib/bundle_announcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_bundle_updates(full_repo_name: str) -> Tuple[Set[RepoResult], Set[RepoRe

except pygithub.RateLimitExceededException:
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
sleep_time = core_rate_limit_reset - datetime.datetime.now()
sleep_time = core_rate_limit_reset - datetime.datetime.utcnow()
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
time.sleep(sleep_time.seconds)
continue
Expand Down
4 changes: 2 additions & 2 deletions adabot/lib/circuitpython_library_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def validate_readthedocs(self, repo):
break
except pygithub.RateLimitExceededException:
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
sleep_time = core_rate_limit_reset - datetime.datetime.now()
sleep_time = core_rate_limit_reset - datetime.datetime.utcnow()
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
time.sleep(sleep_time.seconds)
continue
Expand Down Expand Up @@ -1275,7 +1275,7 @@ def validate_actions_state(self, repo):
return []
except pygithub.RateLimitExceededException:
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
sleep_time = core_rate_limit_reset - datetime.datetime.now()
sleep_time = core_rate_limit_reset - datetime.datetime.utcnow()
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
time.sleep(sleep_time.seconds)

Expand Down