Skip to content

Commit

Permalink
Merge pull request #362 from jepler/fix-ratelimit-timezone
Browse files Browse the repository at this point in the history
Fix ratelimit timezone
  • Loading branch information
dhalbert authored Nov 27, 2023
2 parents e55f7f5 + f2daf93 commit b08b400
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
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

0 comments on commit b08b400

Please sign in to comment.