adafruit / adabot

Adabot is our robot friend who helps Adafruit online
MIT License
13 stars 27 forks source link

Fix ratelimit timezone #362

Closed jepler closed 9 months ago

jepler commented 9 months ago

I discovered that sites that use pygithub to wait for the rate limit reset time were performing incorrect arithmetic between an UTC timestamp and a local timestamp. This led to the sleep taking hours more time than they should.

Some requests are made via pygithub and some via our own API + requests; the requests code was right while the API code was wrong. This made the cron task fail sometimes, depending whether the first rate-limited result was via API or via raw requests.

>>> import os, datetime
>>> import github as pygithub
>>> GH_INTERFACE = pygithub.Github(os.environ.get("ADABOT_GITHUB_ACCESS_TOKEN"))
>>> GH_INTERFACE.get_rate_limit().core.reset - datetime.datetime.now()
datetime.timedelta(seconds=24750, microseconds=356986)
>>> GH_INTERFACE.get_rate_limit().core.reset - datetime.datetime.utcnow()
datetime.timedelta(seconds=3147, microseconds=87271)
jepler commented 9 months ago

we're on an old pygithub. the time zone problem of the rate limit is fixed in 2.0.0 (current is 2.1.x)

https://github.com/PyGithub/PyGithub/pull/2565