mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-23 01:11:56 +01:00
Allow less downloading during dev
This commit is contained in:
parent
67c43193da
commit
789443cb71
@ -99,6 +99,7 @@ nicerExceptions app req send = catch (app req send) $ \e -> do
|
|||||||
-- performs some initialization.
|
-- performs some initialization.
|
||||||
makeFoundation :: Bool -> AppConfig DefaultEnv Extra -> IO App
|
makeFoundation :: Bool -> AppConfig DefaultEnv Extra -> IO App
|
||||||
makeFoundation useEcho conf = do
|
makeFoundation useEcho conf = do
|
||||||
|
let extra = appExtra conf
|
||||||
manager <- newManager
|
manager <- newManager
|
||||||
s <- staticSite
|
s <- staticSite
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ makeFoundation useEcho conf = do
|
|||||||
|
|
||||||
gen <- MWC.createSystemRandom
|
gen <- MWC.createSystemRandom
|
||||||
|
|
||||||
websiteContent' <- if development
|
websiteContent' <- if extraDevDownload extra
|
||||||
then do
|
then do
|
||||||
void $ rawSystem "git"
|
void $ rawSystem "git"
|
||||||
[ "clone"
|
[ "clone"
|
||||||
@ -121,7 +122,7 @@ makeFoundation useEcho conf = do
|
|||||||
"master"
|
"master"
|
||||||
loadWebsiteContent
|
loadWebsiteContent
|
||||||
|
|
||||||
(stackageDatabase', refreshDB) <- loadFromS3 manager
|
(stackageDatabase', refreshDB) <- loadFromS3 (extraDevDownload extra) manager
|
||||||
|
|
||||||
-- Temporary workaround to force content updates regularly, until
|
-- Temporary workaround to force content updates regularly, until
|
||||||
-- distribution of webhooks is handled via consul
|
-- distribution of webhooks is handled via consul
|
||||||
|
|||||||
@ -59,7 +59,10 @@ widgetFile = (if development then widgetFileReload
|
|||||||
widgetFileSettings
|
widgetFileSettings
|
||||||
|
|
||||||
data Extra = Extra
|
data Extra = Extra
|
||||||
|
{ extraDevDownload :: !Bool
|
||||||
|
-- ^ Controls how Git and database resources are downloaded (True means less downloading)
|
||||||
|
}
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
parseExtra :: DefaultEnv -> Object -> Parser Extra
|
parseExtra :: DefaultEnv -> Object -> Parser Extra
|
||||||
parseExtra _ _ = pure Extra
|
parseExtra _ o = Extra <$> o .:? "dev-download" .!= False
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import qualified Data.Conduit.Binary as CB
|
|||||||
import Data.Conduit.Zlib (WindowBits (WindowBits),
|
import Data.Conduit.Zlib (WindowBits (WindowBits),
|
||||||
compress, ungzip)
|
compress, ungzip)
|
||||||
import qualified Hoogle
|
import qualified Hoogle
|
||||||
|
import System.Directory (doesFileExist)
|
||||||
|
|
||||||
filename' :: Text
|
filename' :: Text
|
||||||
filename' = concat
|
filename' = concat
|
||||||
@ -50,13 +51,14 @@ url = concat
|
|||||||
]
|
]
|
||||||
|
|
||||||
-- | Provides an action to be used to refresh the file from S3.
|
-- | Provides an action to be used to refresh the file from S3.
|
||||||
loadFromS3 :: Manager -> IO (IO StackageDatabase, IO ())
|
loadFromS3 :: Bool -- ^ devel mode? if True, won't delete old databases, and won't refresh them either
|
||||||
loadFromS3 man = do
|
-> Manager -> IO (IO StackageDatabase, IO ())
|
||||||
|
loadFromS3 develMode man = do
|
||||||
killPrevVar <- newTVarIO $ return ()
|
killPrevVar <- newTVarIO $ return ()
|
||||||
currSuffixVar <- newTVarIO (1 :: Int)
|
currSuffixVar <- newTVarIO (1 :: Int)
|
||||||
|
|
||||||
let root = "stackage-database"
|
let root = "stackage-database"
|
||||||
handleIO print $ removeTree root
|
unless develMode $ handleIO print $ removeTree root
|
||||||
createTree root
|
createTree root
|
||||||
|
|
||||||
req <- parseUrl $ unpack url
|
req <- parseUrl $ unpack url
|
||||||
@ -67,12 +69,22 @@ loadFromS3 man = do
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
let fp = root </> fpFromText ("database-download-" ++ tshow suffix)
|
let fp = root </> fpFromText ("database-download-" ++ tshow suffix)
|
||||||
putStrLn $ "Downloading database to " ++ fpToText fp
|
isInitial = suffix == 1
|
||||||
withResponse req man $ \res ->
|
toSkip <-
|
||||||
runResourceT
|
if isInitial
|
||||||
$ bodyReaderSource (responseBody res)
|
then do
|
||||||
$= ungzip
|
putStrLn $ "Checking if database exists: " ++ tshow fp
|
||||||
$$ sinkFile fp
|
doesFileExist $ fpToString fp
|
||||||
|
else return False
|
||||||
|
if toSkip
|
||||||
|
then putStrLn "Skipping initial database download"
|
||||||
|
else do
|
||||||
|
putStrLn $ "Downloading database to " ++ fpToText fp
|
||||||
|
withResponse req man $ \res ->
|
||||||
|
runResourceT
|
||||||
|
$ bodyReaderSource (responseBody res)
|
||||||
|
$= ungzip
|
||||||
|
$$ sinkFile fp
|
||||||
putStrLn "Finished downloading database"
|
putStrLn "Finished downloading database"
|
||||||
|
|
||||||
return fp
|
return fp
|
||||||
@ -81,7 +93,7 @@ loadFromS3 man = do
|
|||||||
|
|
||||||
let update = do
|
let update = do
|
||||||
fp <- download
|
fp <- download
|
||||||
db <- openStackageDatabase fp
|
db <- openStackageDatabase fp `onException` removeFile fp
|
||||||
void $ tryIO $ join $ atomically $ do
|
void $ tryIO $ join $ atomically $ do
|
||||||
writeTVar dbvar db
|
writeTVar dbvar db
|
||||||
oldKill <- readTVar killPrevVar
|
oldKill <- readTVar killPrevVar
|
||||||
@ -93,7 +105,7 @@ loadFromS3 man = do
|
|||||||
|
|
||||||
update
|
update
|
||||||
|
|
||||||
return (readTVarIO dbvar, update)
|
return (readTVarIO dbvar, unless develMode update)
|
||||||
|
|
||||||
hoogleKey :: SnapName -> Text
|
hoogleKey :: SnapName -> Text
|
||||||
hoogleKey name = concat
|
hoogleKey name = concat
|
||||||
|
|||||||
@ -5,6 +5,7 @@ Default: &defaults
|
|||||||
|
|
||||||
Development:
|
Development:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
dev-download: true
|
||||||
|
|
||||||
Testing:
|
Testing:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user