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
Changes from 2 commits
be5353a
457506a
32fcbb8
a90dec5
701bd5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
}; | ||
|
||
// Adopted from http://stackoverflow.com/a/3809435/951517 | ||
|
@@ -186,9 +187,14 @@ const createCheckAliveURL = (ruleOptions) => { | |
|
||
// try to fetch again if not reach max retry count | ||
if (currentRetryCount < maxRetryCount) { | ||
// exponential retry | ||
// 0ms -> 100ms -> 200ms -> 400ms -> 800ms ... | ||
await waitTimeMs((currentRetryCount ** 2) * 100); | ||
const retrySeconds = res.headers.get('Retry-After'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we need to prefer Edit: This concern come from default value of maxRetryTime https://github.com/textlint-rule/textlint-rule-no-dead-link/pull/136/files#r739803949
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); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @azu |
||
if (retrySeconds && retrySeconds <= ruleOptions.maxRetryTime) { | ||
await waitTimeMs(retrySeconds * 1000); | ||
} else { | ||
// exponential retry | ||
// 0ms -> 100ms -> 200ms -> 400ms -> 800ms ... | ||
await waitTimeMs(currentRetryCount ** 2 * 100); | ||
} | ||
return isAliveURI(uri, 'GET', maxRetryCount, currentRetryCount + 1); | ||
} | ||
return { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.