Skip to content

Commit

Permalink
feat: log the rate limit after processing a pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Batchelder committed Dec 17, 2021
1 parent c3ff9a1 commit 7e4943e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20211216_174221_nedbat_debug_openedx_fail.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. A new scriv changelog fragment.
- After processing a pull request, the GitHub rate limit is checked and logged:
Rate limit: 5000, used 29, remaining 4971. Reset is at 2021-12-16 23:26:48
4 changes: 3 additions & 1 deletion openedx_webhooks/tasks/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from openedx_webhooks.types import PrDict
from openedx_webhooks.utils import (
log_rate_limit,
paginated_get,
retry_get,
sentry_extra_context,
Expand All @@ -30,7 +31,8 @@
def pull_request_changed_task(_, pull_request):
"""A bound Celery task to call pull_request_changed."""
try:
return pull_request_changed(pull_request)
ret = pull_request_changed(pull_request)
log_rate_limit()
except Exception as exc:
logger.exception("Couldn't pull_request_changed_task")
raise
Expand Down
9 changes: 8 additions & 1 deletion openedx_webhooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from urlobject import URLObject

from openedx_webhooks import logger
from openedx_webhooks.oauth import jira_get
from openedx_webhooks.oauth import get_github_session, jira_get
from openedx_webhooks.types import JiraDict


Expand Down Expand Up @@ -84,6 +84,13 @@ def log_check_response(response, raise_for_status=True):
raise


def log_rate_limit():
"""Get stats from GitHub about the current rate limit, and log them."""
rate = get_github_session().get("/rate_limit").json()['rate']
reset = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(rate['reset']))
logger.info(f"Rate limit: {rate['limit']}, used {rate['used']}, remaining {rate['remaining']}. Reset is at {reset}")


def is_valid_payload(secret: str, signature: str, payload: bytes) -> bool:
"""
Ensure payload is valid according to signature.
Expand Down

0 comments on commit 7e4943e

Please sign in to comment.