Skip to content

Commit

Permalink
Merge pull request #70 from codeforamerica/features/github-soft-rate-…
Browse files Browse the repository at this point in the history
…limits

feat(github): implement handling of soft rate limits
  • Loading branch information
themightychris authored Dec 14, 2022
2 parents 3f4e4eb + 7463089 commit fe9f7ce
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
21 changes: 20 additions & 1 deletion crawler/lib/connections/github.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const axios = require('axios');
const axiosRetryAfter = require('axios-retry-after');

const { GITHUB_ACTOR: githubActor, GITHUB_TOKEN: githubToken } = process.env;

module.exports = axios.create({
const axiosClient = axios.create({
baseURL: 'https://api.github.com',
headers: {
Accept: 'application/vnd.github.mercy-preview+json'
Expand All @@ -11,3 +12,21 @@ module.exports = axios.create({
? { username: githubActor, password: githubToken }
: null
});

axiosClient.interceptors.response.use(null, axiosRetryAfter(axiosClient, {
// GitHub responds with 403 instead of 429 when soft rate limit is hit
isRetryable (error) {
return (
error.response && error.response.status === 403 &&
error.response.headers['retry-after']
);
},

wait (error) {
return new Promise(
resolve => setTimeout(resolve, error.response.headers['retry-after'] * 1000)
);
}
}));

module.exports = axiosClient;
52 changes: 43 additions & 9 deletions crawler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crawler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"author": "Chris Alfano <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.19.2",
"axios": "^1.2.1",
"axios-retry-after": "^2.0.0",
"csv-parser": "^2.3.3",
"gitsheets": "^0.2.2",
"parse-link-header": "^1.0.1",
Expand Down
13 changes: 13 additions & 0 deletions docs/projects/crawler/contributing/crawler.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ The Crawler is built with Node.js and development is primarily supported for [Vi

## After Cloning or Pulling

Make sure you're using node 14:

```bash
node --version
```

On Mac with node installed via Homebrew, you can switch your current shell to node 14:

```bash
brew install node@14
export PATH="/usr/local/opt/node@14/bin:$PATH"
```

Install node modules:

```bash
Expand Down

0 comments on commit fe9f7ce

Please sign in to comment.