[#104] Add maxRetries to configurable options

Problem: maxRetries option was hardcoded in source

Solution: Add it to verify options in config and make new CLI option to override count of retries
This commit is contained in:
Andrei Borzenkov 2022-07-12 19:11:30 +04:00 committed by Constantine Ter-Matevosian
parent 032395007b
commit 2c41713578
No known key found for this signature in database
GPG Key ID: 824C79FC6C4EF3DB
7 changed files with 27 additions and 11 deletions

View File

@ -27,7 +27,8 @@ import Data.Text qualified as T
import Data.Version (showVersion)
import Options.Applicative
(Parser, ReadM, command, eitherReader, execParser, flag, flag', footerDoc, fullDesc, help, helper,
hsubparser, info, infoOption, long, metavar, option, progDesc, short, strOption, switch, value, OptionFields, Mod)
hsubparser, info, infoOption, long, metavar, option, progDesc, short, strOption, switch, value, auto,
OptionFields, Mod)
import Options.Applicative.Help.Pretty (Doc, displayS, fill, fillSep, indent, renderPretty, text)
import Paths_xrefcheck (version)
@ -76,14 +77,16 @@ addTraversalOptions TraversalConfig{..} (TraversalOptions ignored) =
, ..
}
newtype VerifyOptions = VerifyOptions
data VerifyOptions = VerifyOptions
{ voCheckLocalhost :: Maybe Bool
, voMaxRetries :: Maybe Int
}
addVerifyOptions :: VerifyConfig -> VerifyOptions -> VerifyConfig
addVerifyOptions VerifyConfig{..} (VerifyOptions checkLocalhost) =
addVerifyOptions VerifyConfig{..} (VerifyOptions checkLocalhost maxRetries) =
VerifyConfig
{ vcCheckLocalhost = fromMaybe vcCheckLocalhost checkLocalhost
, vcMaxRetries = fromMaybe vcMaxRetries maxRetries
, ..
}
@ -169,6 +172,12 @@ verifyOptionsParser = do
voCheckLocalhost <- flag Nothing (Just True) $
long "check-localhost" <>
help "Check localhost links."
voMaxRetries <- option (Just <$> auto) $
long "retries" <>
metavar "INT" <>
value Nothing <>
help "How many attempts to retry an external link after getting \
\a \"429 Too Many Requests\" response."
return VerifyOptions{..}
dumpConfigOptions :: Parser Command

View File

@ -65,6 +65,7 @@ data VerifyConfig = VerifyConfig
, vcDefaultRetryAfter :: Time Second
-- ^ Default Retry-After delay, applicable when we receive a 429 response
-- and it does not contain a @Retry-After@ header.
, vcMaxRetries :: Int
}
normaliseVerifyConfigFilePaths :: VerifyConfig -> VerifyConfig

View File

@ -59,6 +59,10 @@ verification:
# wait this amount of time before attempting to verify the link again.
defaultRetryAfter: 30s
# How many attempts to retry an external link after getting
# a "429 Too Many Requests" response.
maxRetries: 3
# Parameters of scanners for various file types.
scanners:
markdown:

View File

@ -300,7 +300,7 @@ verifyReference
retryVerification numberOfRetries resIO = do
res@(VerifyResult ves) <- resIO
let toRetry = any isFixable ves && numberOfRetries < maxRetries
let toRetry = any isFixable ves && numberOfRetries < vcMaxRetries
currentRetryAfter = extractRetryAfterInfo res
let moveProgress = alterOverallProgress numberOfRetries
@ -344,17 +344,17 @@ verifyReference
-> Progress a
-> Progress a
alterProgressErrors res@(VerifyResult ves) retryNumber
| maxRetries == 0 =
| vcMaxRetries == 0 =
if ok then id
else incProgressUnfixableErrors
| retryNumber == 0 =
if ok then id
else if fixable then incProgressFixableErrors
else incProgressUnfixableErrors
| retryNumber == maxRetries =
| retryNumber == vcMaxRetries =
if ok then decProgressFixableErrors
else fixableToUnfixable
-- 0 < retryNumber < maxRetries
-- 0 < retryNumber < vcMaxRetries
| otherwise =
if ok then decProgressFixableErrors
else if fixable then id
@ -368,10 +368,6 @@ verifyReference
VerifyResult [ExternalHttpTooManyRequests retryAfter] -> retryAfter
_ -> vcDefaultRetryAfter
-- | Maximum number of retries available until a fixable error becomes unfixable.
-- Soon to become a configurable value.
maxRetries = 20
checkRef mAnchor referredFile = verifying $ do
checkReferredFileExists referredFile
case M.lookup referredFile repoInfo of

View File

@ -50,6 +50,10 @@ verification:
# wait this amount of time before attempting to verify the link again.
defaultRetryAfter: 30s
# How many attempts to retry an external link after getting
# a "429 Too Many Requests" response.
maxRetries: 3
# Parameters of scanners for various file types.
scanners:
markdown:

View File

@ -14,6 +14,7 @@ verification:
checkLocalhost: false
ignoreAuthFailures: true
defaultRetryAfter: 30s
maxRetries: 3
scanners:
markdown:

View File

@ -14,6 +14,7 @@ verification:
checkLocalhost: true
ignoreAuthFailures: true
defaultRetryAfter: 30s
maxRetries: 3
scanners:
markdown: