Skip to content

Commit

Permalink
[#239][#249] Simplify progress bar interface
Browse files Browse the repository at this point in the history
Problem: After changing the progress bar interface to require progress
unit witnesses, some functions related to an anonymous task timestamp
also started to require a progress unit witness, which complicates its
usage unnecessarily.

Solution: Do not require a progress unit witness for setTaskTimestamp
and getTaskTimestamp.
  • Loading branch information
aeqz committed Jan 25, 2023
1 parent aec4141 commit 8013bf7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Xrefcheck/Progress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ reportRetry item Progress{..} = Progress
, ..
}

setTaskTimestamp :: w -> Time Second -> Time Second -> Progress a w -> Progress a w
setTaskTimestamp _ ttc startTime Progress{..} = Progress
setTaskTimestamp :: Time Second -> Time Second -> Progress a w -> Progress a w
setTaskTimestamp ttc startTime Progress{..} = Progress
{ pTaskTimestamp = Just (TaskTimestamp ttc startTime)
, ..
}

getTaskTimestamp :: w -> Progress a w -> Maybe TaskTimestamp
getTaskTimestamp _ = pTaskTimestamp
getTaskTimestamp :: Progress a w -> Maybe TaskTimestamp
getTaskTimestamp = pTaskTimestamp

removeTaskTimestamp :: Progress a w -> Progress a w
removeTaskTimestamp Progress{..} = Progress
Expand Down
4 changes: 2 additions & 2 deletions src/Xrefcheck/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,10 @@ verifyReference
RIExternal (ELUrl url) -> VerifyProgress{ vrExternal =
let vrExternalAdvanced = moveProgress url vrExternal
in case mbRetryData of
Just (now, retryAfter) -> case getTaskTimestamp url vrExternal of
Just (now, retryAfter) -> case getTaskTimestamp vrExternal of
Just (TaskTimestamp ttc start)
| retryAfter +:+ now <= ttc +:+ start -> vrExternalAdvanced
_ -> setTaskTimestamp url retryAfter now vrExternalAdvanced
_ -> setTaskTimestamp retryAfter now vrExternalAdvanced
Nothing -> vrExternalAdvanced, .. }
, ()
)
Expand Down
12 changes: 6 additions & 6 deletions tests/Test/Xrefcheck/TooManyRequestsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test_tooManyRequests = testGroup "429 response tests"
setRef <- newIORef S.empty
progressRef <- newIORef VerifyProgress
{ vrLocal = initProgress 0
, vrExternal = setTaskTimestamp "" (sec 3) (now -:- sec 1.5)
, vrExternal = setTaskTimestamp (sec 3) (now -:- sec 1.5)
. reportSuccess ""
$ initProgress 2
}
Expand All @@ -57,7 +57,7 @@ test_tooManyRequests = testGroup "429 response tests"
setRef
progressRef
progress <- vrExternal <$> readIORef progressRef
let ttc = ttTimeToCompletion <$> getTaskTimestamp "" progress
let ttc = ttTimeToCompletion <$> getTaskTimestamp progress
flip assertBool (ttc == Just (sec 2)) $
"Expected time to completion be equal to " ++ show (Just $ sec 2) ++
", but instead it's " ++ show ttc
Expand All @@ -71,7 +71,7 @@ test_tooManyRequests = testGroup "429 response tests"
setRef <- newIORef S.empty
progressRef <- newIORef VerifyProgress
{ vrLocal = initProgress 0
, vrExternal = setTaskTimestamp "" (sec 2) (now -:- sec 1.5)
, vrExternal = setTaskTimestamp (sec 2) (now -:- sec 1.5)
. reportSuccess ""
$ initProgress 2
}
Expand All @@ -80,7 +80,7 @@ test_tooManyRequests = testGroup "429 response tests"
setRef
progressRef
progress <- vrExternal <$> readIORef progressRef
let ttc = fromMaybe (sec 0) $ ttTimeToCompletion <$> getTaskTimestamp "" progress
let ttc = fromMaybe (sec 0) $ ttTimeToCompletion <$> getTaskTimestamp progress
flip assertBool (sec 3 <= ttc && ttc <= sec 4) $
"Expected time to completion be within range (seconds): 3 <= x <= 4" ++
", but instead it's " ++ show ttc
Expand All @@ -95,7 +95,7 @@ test_tooManyRequests = testGroup "429 response tests"
setRef <- newIORef S.empty
progressRef <- newIORef VerifyProgress
{ vrLocal = initProgress 0
, vrExternal = setTaskTimestamp "" (sec 1) (now -:- sec 1.5)
, vrExternal = setTaskTimestamp (sec 1) (now -:- sec 1.5)
. reportSuccess ""
$ initProgress 2
}
Expand All @@ -104,7 +104,7 @@ test_tooManyRequests = testGroup "429 response tests"
setRef
progressRef
progress <- vrExternal <$> readIORef progressRef
let ttc = ttTimeToCompletion <$> getTaskTimestamp "" progress
let ttc = ttTimeToCompletion <$> getTaskTimestamp progress
flip assertBool (ttc == Just (sec 0)) $
"Expected time to completion be 0 seconds" ++
", but instead it's " ++ show ttc
Expand Down

0 comments on commit 8013bf7

Please sign in to comment.