Skip to content

Commit

Permalink
Add (and document) a quickly option which does not wait for the rate …
Browse files Browse the repository at this point in the history
…limiter.
  • Loading branch information
holly-cummins committed Nov 21, 2023
1 parent 72ece84 commit 243d648
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ nvm use 18
Information is more complete if a GitHub access token is provided. It should only be granted read access.
Set it as an environment variable called `GITHUB_TOKEN`. (In the CI, this will be provided by the platform.)

## Caching

The site pulls down a lot of content through the GitHub API.
A full build of the site will trigger the rate limiter several times. Each time the rate limiter is hit, the build needs to wait an hour for it to roll over.
Because of this, a fresh build could take two or three hours – be prepared! To build more quickly (but with incomplete information), use the `npm run develop:quickly` command.

The build caches GitHub content in a cache in the `.cache-github-api/` directory, so once a build has been done, subsequent builds should be quicker.
Most cache contents have a lifespan of a few days (with some jitter so everything doesn't expire at once).

In one terminal, run tests
```
npm install
Expand All @@ -41,6 +50,8 @@ In another terminal, run the site
npm run develop
```

(or `npm run develop:quickly` if you're in a hurry and don't need all the source control data)

You can then see changes live on http://localhost:8000.

# Local production-like development
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"scripts": {
"build": "cp ./node_modules/gatsby-page-utils/dist/apply-trailing-slash-option.js ./node_modules/gatsby-page-utils && gatsby build",
"develop": "gatsby develop",
"develop:quickly": "DONT_WAIT=true gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "cp ./node_modules/gatsby-page-utils/dist/apply-trailing-slash-option.js ./node_modules/gatsby-page-utils && gatsby develop",
"serve": "gatsby serve",
Expand Down
11 changes: 7 additions & 4 deletions plugins/github-enricher/github-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const RATE_LIMIT_PREQUERY = `rateLimit {
}`

let resetTime
const allowSlowBuild = !process.env.DONT_WAIT

// We can add more errors we know are non-recoverable here, which should help build times
const isRecoverableError = (ghBody, params) => {
Expand Down Expand Up @@ -46,13 +47,15 @@ async function tolerantFetch(url, params, isSuccessful, getContents) {
if (!isSuccessful(ghBody) && isRecoverableError(ghBody, params)) {
const responseString = JSON.stringify(ghBody)

if (responseString?.includes("RATE_LIMITED") && resetTime) {
if (allowSlowBuild && responseString?.includes("RATE_LIMITED") && resetTime) {
console.warn("Hit the rate limit. Waiting until", resetTime)
await waitUntil(resetTime)
}
retry(
`Unsuccessful GitHub fetch for ${url} - response is ${responseString}`
)
if (allowSlowBuild) {
retry(
`Unsuccessful GitHub fetch for ${url} - response is ${responseString}`
)
}
}
return ghBody
},
Expand Down

0 comments on commit 243d648

Please sign in to comment.