Skip to content

Commit

Permalink
Wait and retry on secondary limits (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher authored Jul 1, 2022
1 parent 14ed2b3 commit 1a984f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test_tap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: actions/cache@v2
with:
path: .venv
key: venv-2-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ matrix.python-version }}
key: venv-3-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ matrix.python-version }}
- name: Install dependencies
run: |
poetry install
Expand Down
11 changes: 11 additions & 0 deletions tap_github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import collections
import inspect
import random
import re
import time
from types import FrameType
from typing import Any, Dict, Iterable, List, Optional, cast
from urllib.parse import parse_qs, urlparse
Expand Down Expand Up @@ -203,6 +205,15 @@ def validate_response(self, response: requests.Response) -> None:
# Raise an error to force a retry with the new token.
raise RetriableAPIError(msg, response)

# Retry on secondary rate limit
if (
response.status_code == 403
and "secondary rate limit" in str(response.content).lower()
):
# Wait about a minute and retry
time.sleep(60 + 30 * random.random())
raise RetriableAPIError(msg, response)

# The GitHub API randomly returns 401 Unauthorized errors, so we try again.
if (
response.status_code == 401
Expand Down

0 comments on commit 1a984f5

Please sign in to comment.