Skip to content

Commit

Permalink
Added control for secondary rate limit (paritytech#15)
Browse files Browse the repository at this point in the history
Sometimes the secondary rate limit stop the action from working.

This limit is quite unpredictable, sometimes it hits on small requests
when GitHub's api is being too active, or sometimes it doesn't appear at
all.

What I do know is that it appears when a similar call is done actively
without a break.

This change adds a one minute break for every 5 pages that has been
iterated, which, in my experiments, seems to have stopped the error from
appearing.

I have also updated all the GitHub actions to their latest versions.
  • Loading branch information
Bullrich authored Apr 15, 2024
1 parent 7084c14 commit b01bceb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/deploy-page.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Deploy page
name: Generate metrics

on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
org:
description: 'Organization'
description: "Organization"
type: string
required: false
default: "polkadot-fellows"
repo:
description: 'Repository'
description: "Repository"
type: string
required: false
default: "runtimes"
Expand All @@ -33,11 +33,11 @@ jobs:
owner: ${{ github.event.inputs.org }}
repo: ${{ github.event.inputs.repo }}
- name: Setup Pages
uses: actions/configure-pages@v2
uses: actions/configure-pages@v5.0.0
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3.0.1
with:
path: ./
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v4.0.5
6 changes: 3 additions & 3 deletions .github/workflows/javascript-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
runs-on: ubuntu-latest
name: running ${{ matrix.command }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.1
- name: Use node 20
uses: actions/setup-node@v4
uses: actions/setup-node@v4.0.2
with:
node-version: 20
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
uses: actions/cache@v4.0.2
env:
cache-name: cache-node-modules
with:
Expand Down
14 changes: 14 additions & 0 deletions src/github/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ export class RepositoryApi {
...this.repo,
},
);

const totalPages =
Math.floor(query.repository.pullRequests.totalCount / 100) + 1;
this.logger.info(`Querying page ${++currentPage}/${totalPages}`);
const { nodes, pageInfo } = query.repository.pullRequests;
prs.push(...nodes);
hasNextPage = pageInfo.hasNextPage;
cursor = pageInfo.endCursor;
if (currentPage % 5 === 0) {
this.logger.debug("Pausing for one minute to not hit secondary limits");
await new Promise<void>((resolve) =>
setTimeout(() => resolve(), 60_000),
);
}
} while (hasNextPage);

this.logger.info(`Found information for ${prs.length} pull requests`);
Expand Down Expand Up @@ -93,6 +100,13 @@ export class RepositoryApi {
issues.push(...nodes);
hasNextPage = pageInfo.hasNextPage;
cursor = pageInfo.endCursor;

if (currentPage % 5 === 0) {
this.logger.debug("Pausing for one minute to not hit secondary limits");
await new Promise<void>((resolve) =>
setTimeout(() => resolve(), 60_000),
);
}
} while (hasNextPage);

this.logger.info(`Found information for ${issues.length} issues`);
Expand Down

0 comments on commit b01bceb

Please sign in to comment.