Skip to content

Commit

Permalink
fix(scripts): add retry rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoh committed Aug 19, 2024
1 parent 6a8ab85 commit 59da585
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/package-lock.json

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

1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"dependencies": {
"@octokit/rest": "^21.0.1",
"axios-retry": "^4.5.0",
"change-case": "^5.4.4",
"fast-xml-parser": "^4.4.1",
"glob": "^11.0.0",
Expand Down
15 changes: 15 additions & 0 deletions scripts/validate-sgid-index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axiosRetry from 'axios-retry';
import { GoogleAuth, auth } from 'google-auth-library';
import { GoogleSpreadsheet } from 'google-spreadsheet';
import jsonToMarkdown from 'json-to-markdown-table';
Expand All @@ -7,6 +8,17 @@ import * as tsImport from 'ts-import';
import { v4 as uuid } from 'uuid';
import { slugify, validateOpenDataUrl, validateOpenSgidTableName, validateUrl } from './utilities.mjs';

function retry(client) {
axiosRetry(client, {
retries: 7,
retryDelay: (retryCount) => {
const randomNumberMS = _.random(1000, 8000);
return Math.min(4 ** retryCount + randomNumberMS, maximumBackoff);
},
retryCondition: (error) => error.response.status === 429,
});
}

const downloadMetadata = await tsImport.load('../src/data/downloadMetadata.ts');

const spreadsheetId = '11ASS7LnxgpnD0jN4utzklREgMf1pcvYjcXcIcESHweQ';
Expand All @@ -26,6 +38,9 @@ if (process.env.GITHUB_ACTIONS) {

console.log('loading spreadsheet');
const spreadsheet = new GoogleSpreadsheet(spreadsheetId, client);
retry(spreadsheet.sheetsApi);
retry(spreadsheet.driveApi);

await spreadsheet.loadInfo();
const worksheet = spreadsheet.sheetsByTitle['SGID Index'];

Expand Down

0 comments on commit 59da585

Please sign in to comment.