Skip to content

Commit 4f69d1d

Browse files
committed
Replace drRetries with drRetryPolicy in DownloadRequest
1 parent 06dda47 commit 4f69d1d

6 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/Network/HTTP/Download.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Network.HTTP.Download
55
( verifiedDownload
66
, DownloadRequest(..)
7-
, drRetriesDefault
7+
, drRetryPolicyDefault
88
, HashCheck(..)
99
, CheckHexDigest(..)
1010
, LengthCheck
@@ -70,7 +70,7 @@ download req destpath = do
7070
{ drRequest = req
7171
, drHashChecks = []
7272
, drLengthCheck = Nothing
73-
, drRetries = drRetriesDefault
73+
, drRetryPolicy = drRetryPolicyDefault
7474
}
7575
let progressHook _ = return ()
7676
verifiedDownload downloadReq destpath progressHook

src/Network/HTTP/Download/Verified.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
module Network.HTTP.Download.Verified
1010
( verifiedDownload
1111
, DownloadRequest(..)
12-
, drRetriesDefault
12+
, drRetryPolicyDefault
1313
, HashCheck(..)
1414
, CheckHexDigest(..)
1515
, LengthCheck
@@ -28,7 +28,7 @@ import Control.Monad
2828
import Control.Monad.Catch
2929
import Control.Monad.IO.Class
3030
import Control.Monad.Reader
31-
import Control.Retry (recovering,limitRetries)
31+
import Control.Retry (recovering,limitRetries,RetryPolicy,constantDelay)
3232
import Control.Applicative
3333
import Crypto.Hash
3434
import Crypto.Hash.Conduit (sinkHash)
@@ -53,13 +53,13 @@ data DownloadRequest = DownloadRequest
5353
{ drRequest :: Request
5454
, drHashChecks :: [HashCheck]
5555
, drLengthCheck :: Maybe LengthCheck
56-
, drRetries :: Int
56+
, drRetryPolicy :: RetryPolicy
5757
}
58-
deriving Show
5958

60-
-- | Default to retrying thrice.
61-
drRetriesDefault :: Int
62-
drRetriesDefault = 3
59+
-- | Default to retrying thrice with a short constant delay.
60+
drRetryPolicyDefault :: RetryPolicy
61+
drRetryPolicyDefault = limitRetries 3 <> constantDelay onehundredMilliseconds
62+
where onehundredMilliseconds = 100000
6363

6464
data HashCheck = forall a. (Show a, HashAlgorithm a) => HashCheck
6565
{ hashCheckAlgorithm :: a
@@ -200,7 +200,7 @@ verifiedDownload DownloadRequest{..} destpath progressSink = do
200200
liftIO $ whenM' getShouldDownload $ do
201201
createDirectoryIfMissing True dir
202202
withBinaryFile fptmp WriteMode $ \h -> do
203-
recovering (limitRetries drRetries) [const $ Handler alwaysRetryHttp] $
203+
recovering drRetryPolicy [const $ Handler alwaysRetryHttp] $
204204
flip runReaderT env $
205205
withResponse req (go h)
206206
renameFile fptmp fp

src/Stack/Fetch.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fetchPackages' mdistDir toFetchAll = do
432432
{ drRequest = req
433433
, drHashChecks = map toHashCheck $ maybeToList (tfSHA512 toFetch)
434434
, drLengthCheck = fmap fromIntegral $ tfSize toFetch
435-
, drRetries = drRetriesDefault
435+
, drRetryPolicy = drRetryPolicyDefault
436436
}
437437
let progressSink _ = do
438438
liftIO $ runInBase $ $logInfo $ packageIdentifierText ident <> ": download"

src/Stack/Setup.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import qualified Data.Yaml as Yaml
4949
import Distribution.System (OS (..), Arch (..), Platform (..))
5050
import Distribution.Text (simpleParse)
5151
import Network.HTTP.Client.Conduit
52-
import Network.HTTP.Download (verifiedDownload, DownloadRequest(..), drRetriesDefault)
52+
import Network.HTTP.Download (verifiedDownload, DownloadRequest(..), drRetryPolicyDefault)
5353
import Path
5454
import Path.IO
5555
import Prelude -- Fix AMP warning
@@ -720,7 +720,7 @@ chattyDownload label url path = do
720720
{ drRequest = req
721721
, drHashChecks = []
722722
, drLengthCheck = Nothing
723-
, drRetries = drRetriesDefault
723+
, drRetryPolicy = drRetryPolicyDefault
724724
}
725725
runInBase <- liftBaseWith $ \run -> return (void . run)
726726
x <- verifiedDownload dReq path (chattyDownloadProgress runInBase)

src/test/Network/HTTP/Download/VerifiedSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Network.HTTP.Download.VerifiedSpec where
44
import Crypto.Hash
55
import Control.Monad (unless)
66
import Control.Monad.Trans.Reader
7+
import Control.Retry (limitRetries)
78
import Data.Maybe
89
import Network.HTTP.Client.Conduit
910
import Network.HTTP.Download.Verified
@@ -34,7 +35,7 @@ exampleReq = fromMaybe (error "exampleReq") $ do
3435
{ drRequest = req
3536
, drHashChecks = [exampleHashCheck]
3637
, drLengthCheck = Just exampleLengthCheck
37-
, drRetries = 1
38+
, drRetryPolicy = limitRetries 1
3839
}
3940

4041
exampleHashCheck :: HashCheck
@@ -155,7 +156,7 @@ spec = beforeAll setup $ afterAll teardown $ do
155156
{ drRequest = req
156157
, drHashChecks = []
157158
, drLengthCheck = Nothing
158-
, drRetries = 1
159+
, drRetryPolicy = limitRetries 1
159160
}
160161
let go = runWith manager $ verifiedDownload dReq dest exampleProgressHook
161162
doesFileExist destFp `shouldReturn` False

stack.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ test-suite stack-test
235235
, optparse-applicative
236236
, bytestring
237237
, QuickCheck
238+
, retry >= 0.6
238239
default-language: Haskell2010
239240

240241
test-suite stack-integration-test

0 commit comments

Comments
 (0)