Skip to content

Commit

Permalink
fix: increase reqest retries (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Apr 11, 2022
1 parent 8bc4e0f commit e3e6fa1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5771,7 +5771,8 @@ try {
}
var GithubClient = class {
constructor() {
this.MAX_RETRIES = 5;
this.MAX_RETRIES = 30;
this.RETRY_SEEP_TIME_MS = 1e4;
this.octokit = import_github.getOctokit(githubToken);
}
async requestAndRetry(request) {
Expand All @@ -5780,7 +5781,7 @@ var GithubClient = class {
return await request();
} catch (error2) {
core.info(`Request failed. Retrying ${retryCount}/${this.MAX_RETRIES}.`);
await sleep(5e3);
await sleep(this.RETRY_SEEP_TIME_MS);
}
}
return await request();
Expand Down
7 changes: 5 additions & 2 deletions src/github-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class GithubClient {
private octokit: ReturnType<typeof getOctokit>;

/** Indicates how many times failed request is retried */
private MAX_RETRIES = 5;
private MAX_RETRIES = 30;

/** Indicates how many seconds should be waited before failed request is retried */
private RETRY_SEEP_TIME_MS = 10000;

constructor() {
this.octokit = getOctokit(githubToken);
Expand All @@ -33,7 +36,7 @@ class GithubClient {
core.info(
`Request failed. Retrying ${retryCount}/${this.MAX_RETRIES}.`
);
await sleep(5000);
await sleep(this.RETRY_SEEP_TIME_MS);
}
}

Expand Down
12 changes: 6 additions & 6 deletions test/github-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe('github-client', () => {
expect(onIssueCreated).not.toHaveBeenCalled();
});

test('should recover from 5x API errors', async () => {
// Request should fail 5 times
times(5)(() => mockApiError.mockReturnValueOnce(true));
test('should recover from 30x API errors', async () => {
// Request should fail 30 times
times(30)(() => mockApiError.mockReturnValueOnce(true));
mockNoExistingIssues.mockReturnValueOnce(true);

jest.useFakeTimers();
Expand All @@ -85,14 +85,14 @@ describe('github-client', () => {
});
});

test('should fail request after 6x failures', async () => {
times(6)(() => mockApiError.mockReturnValueOnce(true));
test('should fail request after 31x failures', async () => {
times(31)(() => mockApiError.mockReturnValueOnce(true));
mockNoExistingIssues.mockReturnValueOnce(true);

jest.useFakeTimers();
const request = GithubClient.postResults(body);

await waitFor(() => expect(mockApiError).toHaveBeenCalledTimes(6));
await waitFor(() => expect(mockApiError).toHaveBeenCalledTimes(31));
jest.useRealTimers();

await expect(request).rejects.toMatchInlineSnapshot(`[HttpError]`);
Expand Down

0 comments on commit e3e6fa1

Please sign in to comment.