Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check-member-data: skip 429 responses #384

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
fetch-depth: 0
- name: Run npm install
run: npm install
# - name: Check all member data
# run: ./src/memberData/bin/checkMembers.ts
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check all member data
run: ./src/memberData/bin/checkMembers.ts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: mfinelli/setup-imagemagick@v6
- name: Build generated resources
run: ./bin/make-generated-resources
Expand Down
24 changes: 20 additions & 4 deletions src/memberData/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,29 @@ export function isReportOverdue(member: Member) {
return latestReportEndDate.isBefore(dayjs().subtract(1, 'year'));
}

async function makeHeadRequest(url: string) {
return fetch(url, {
method: 'HEAD',
});
}

export async function isMemberUrlNotRetrievable(member: Member) {
const MAX_N_ATTEMPTS = 5;
let n_attempts = 0;
while (true) {
try {
console.log(`GET ${member.url}`);
const res = await fetch(member.url, { method: 'HEAD' })
const res = await makeHeadRequest(member.url);
if (res.status == 429) {
console.log('Got 429, skipping...');
break;
}
if (res.status != 200) {
throw new Error(`Status code was ${res.status}`);
throw new Error(`Status code was ${res.status}`, { cause: res });
}
break;
} catch (e) {
console.error(e);
n_attempts += 1;
if (n_attempts >= MAX_N_ATTEMPTS) {
return true;
Expand All @@ -143,12 +154,17 @@ export async function isReportUrlNotRetrievable(member: Member) {
while (true) {
try {
console.log(`GET ${report.url}`);
const res = await fetch(report.url, { method: 'HEAD' })
const res = await makeHeadRequest(report.url);
if (res.status == 429) {
console.log('Got 429, skipping...');
break;
}
if (res.status != 200) {
throw new Error(`Status code was ${res.status}`);
throw new Error(`Status code was ${res.status}`, { cause: res });
}
break;
} catch (e) {
console.error(e);
n_attempts += 1;
if (n_attempts >= MAX_N_ATTEMPTS) {
return true;
Expand Down