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

feat(rule): add maxRetryTime option #136

Merged
merged 5 commits into from Nov 8, 2021
Merged

feat(rule): add maxRetryTime option #136

merged 5 commits into from Nov 8, 2021

Conversation

chick-p
Copy link
Contributor

@chick-p chick-p commented Oct 31, 2021

Fix #135

I've not added this test case.
Because I expect this test case occurs timeout.
Ref. textlint/textlint#781

// exponential retry
// 0ms -> 100ms -> 200ms -> 400ms -> 800ms ...
await waitTimeMs((currentRetryCount ** 2) * 100);
const retrySeconds = res.headers.get('Retry-After');
Copy link
Member

@azu azu Oct 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need to prefer Retry-After if the response header includes Retry-After.

Edit: This concern come from default value of maxRetryTime https://github.com/textlint-rule/textlint-rule-no-dead-link/pull/136/files#r739803949
So, we not need to change the logics if we change the default value.

probably, next code. It may be subtle.

const retrySeconds = res.headers.get('Retry-After');
// If the response has `Retry-After` header, prefer it
// else exponential retry: 0ms -> 100ms -> 200ms -> 400ms -> 800ms ...
const retryWaitTimeMs = retrySeconds !== null ? retrySeconds * 1000 : currentRetryCount ** 2 * 100;
const maxRetryTimeMs = ruleOptions.maxRetryTime * 1000;
if (retryWaitTime <= maxRetryTimeMs) {
  await waitTimeMs(currentRetryCount ** 2 * 100);
}
return isAliveURI(uri, 'GET', maxRetryCount, currentRetryCount + 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azu
Thank you for your comment.
I rewrite the code as you said.

@@ -20,7 +20,8 @@ const DEFAULT_OPTIONS = {
interval: 500, // The length of time in milliseconds before the interval count resets. Must be finite. [Experimental]
intervalCap: 8, // The max number of runs in the given interval of time. [Experimental]
keepAlive: false, // {boolean} if it is true, use keepAlive for checking request [Experimental]
userAgent: 'textlint-rule-no-dead-link/1.0' // {String} a UserAgent
userAgent: 'textlint-rule-no-dead-link/1.0', // {String} a UserAgent,
maxRetryTime: 0, // (number) The max of waiting seconds for retry, if response returns `After-Retry` header.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default value means that we will ignore Retry-After by default.
I think that we should consider Retry-After header if the server response it.

Increase maxRetryTime to 10 or 30?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set it to 10.

I've set 0 to not impact those who are already using it.
But I understand that After-Retry value should be used.

@chick-p chick-p changed the title feat(rule): add option maxRetryTime option feat(rule): add maxRetryTime option Nov 5, 2021
@azu azu merged commit 9f9c636 into textlint-rule:master Nov 8, 2021
@azu
Copy link
Member

azu commented Nov 8, 2021

Thanks!

@azu
Copy link
Member

azu commented Nov 8, 2021

Release Release v4.8.0 · textlint-rule/textlint-rule-no-dead-link 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

429 too many requests
2 participants