Skip to content

Commit 763a8c2

Browse files
committed
Retry on 429
1 parent 290de40 commit 763a8c2

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

plugins/github-enricher/gatsby-node.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const promiseRetry = require("promise-retry")
2+
13
const followRedirect = require("follow-redirect-url")
24

35
const gh = require("parse-github-url")
@@ -24,6 +26,9 @@ const defaultOptions = {
2426
nodeType: "Extension",
2527
}
2628

29+
const RETRY_OPTIONS = { retries: 5, minTimeout: 75 * 1000, factor: 5 }
30+
31+
2732
// To avoid hitting the git rate limiter retrieving information we already know, cache what we can
2833
const DAY_IN_SECONDS = 24 * 60 * 60
2934

@@ -694,17 +699,11 @@ const getMetadataPathNoCache = async (coords, groupId, artifactId) => {
694699
const getIssueInformation = async (coords, labels, scmUrl) => {
695700
const key = labels ? labels.map(label => `"${label}"`).join() : `${coords.owner}-${coords.name}`
696701

697-
// Diagnostic - bypass the cache
698-
if (coords?.name?.includes("debezium") || coords?.name?.includes("optaplanner")) {
699-
console.log("Bypassing issue url cache for", coords.name)
700-
return getIssueInformationNoCache(coords, labels, scmUrl)
701-
} else {
702+
return await issueCountCache.getOrSet(
703+
key,
704+
() => getIssueInformationNoCache(coords, labels, scmUrl)
705+
)
702706

703-
return await issueCountCache.getOrSet(
704-
key,
705-
() => getIssueInformationNoCache(coords, labels, scmUrl)
706-
)
707-
}
708707
}
709708

710709
function normaliseUrl(issuesUrl) {
@@ -783,13 +782,18 @@ const maybeIssuesUrl = async (issues, issuesUrl) => {
783782
}
784783

785784
const isRedirectToPulls = async (issuesUrl) => {
786-
// Being a valid url may not be enough, we also want to check for redirects to /pulls
787-
const urls = await followRedirect.startFollowing(issuesUrl)
788-
console.log("URL chain for", issuesUrl, "is", urls)
789-
const finalUrl = urls[urls.length - 1]
790-
console.log("Final URL is", finalUrl, "which means", (finalUrl.url.includes("/pulls")))
785+
return await promiseRetry(async () => {
786+
// Being a valid url may not be enough, we also want to check for redirects to /pulls
787+
const urls = await followRedirect.startFollowing(issuesUrl)
788+
console.log("URL chain for", issuesUrl, "is", urls)
789+
const finalUrl = urls[urls.length - 1]
790+
if (finalUrl.status === 429) {
791+
throw new Error("Too many requests, need to retry")
792+
}
793+
console.log("Final URL is", finalUrl, "which means", (finalUrl.url.includes("/pulls")))
791794

792-
return (finalUrl.url.includes("/pulls"))
795+
return (finalUrl.url.includes("/pulls"))
796+
}, RETRY_OPTIONS)
793797
}
794798

795799
// This combines the sponsor opt-in information (which we only fully have after processing all nodes) with the companies and sponsor information for individual nodes,

0 commit comments

Comments
 (0)