mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-12 04:08:29 +01:00
Hooked DeprecationInfo update procedure into appLoadCabalFiles
This commit is contained in:
parent
07fb2c9290
commit
ed23d5edc7
@ -12,6 +12,7 @@ import Control.Exception (catch)
|
||||
import Control.Monad.Logger (runLoggingT, LoggingT, defaultLogStr)
|
||||
import Data.BlobStore (fileStore, storeWrite, cachedS3Store)
|
||||
import Data.Hackage
|
||||
import Data.Hackage.DeprecationInfo
|
||||
import Data.Unpacking (newDocUnpacker, createHoogleDatabases)
|
||||
import Data.WebsiteContent
|
||||
import Data.Slug (SnapSlug (..), safeMakeSlug, HasGenIO)
|
||||
@ -299,6 +300,17 @@ appLoadCabalFiles updateDB forceUpdate env dbconf p = do
|
||||
let runDB' :: SqlPersistT (ResourceT (ReaderT env (LoggingT IO))) a
|
||||
-> ReaderT env (LoggingT IO) a
|
||||
runDB' = runResourceT . flip (Database.Persist.runPool dbconf) p
|
||||
|
||||
$logInfo "Updating deprecation tags"
|
||||
loadDeprecationInfo >>= \ei -> case ei of
|
||||
Left e -> $logError (pack e)
|
||||
Right info -> runDB' $ do
|
||||
deleteWhere ([] :: [Filter Deprecated])
|
||||
insertMany_ (deprecations info)
|
||||
deleteWhere ([] :: [Filter Suggested])
|
||||
insertMany_ (suggestions info)
|
||||
$logInfo "Finished updating deprecation tags"
|
||||
|
||||
uploadHistory0 <- runDB' $ selectSource [] [] $$ sinkUploadHistory
|
||||
let toMDPair (E.Value name, E.Value version, E.Value hash') =
|
||||
(name, (version, hash'))
|
||||
@ -320,6 +332,7 @@ appLoadCabalFiles updateDB forceUpdate env dbconf p = do
|
||||
deleteWhere [DependencyUser ==. metadataName md]
|
||||
insertMany_ $ flip map (metadataDeps md) $ \dep ->
|
||||
Dependency (PackageName dep) (metadataName md)
|
||||
|
||||
case eres of
|
||||
Left e -> $logError $ tshow e
|
||||
Right () -> return ()
|
||||
|
||||
@ -2,10 +2,11 @@
|
||||
-- into model data to be stored in the database.
|
||||
module Data.Hackage.DeprecationInfo
|
||||
( HackageDeprecationInfo(..)
|
||||
, loadDeprecationInfo
|
||||
) where
|
||||
|
||||
import Prelude
|
||||
import Data.Aeson
|
||||
import ClassyPrelude.Yesod
|
||||
import Data.Aeson as Aeson
|
||||
import Model
|
||||
import Types
|
||||
|
||||
@ -28,13 +29,12 @@ data DeprecationRecord = DeprecationRecord {
|
||||
}
|
||||
|
||||
instance FromJSON DeprecationRecord where
|
||||
parseJSON j = do
|
||||
obj <- parseJSON j
|
||||
package <- (obj .: "deprecated-package") >>= parsePackageName
|
||||
inFavourOf <- (obj .: "in-favour-of") >>= mapM parsePackageName
|
||||
parseJSON = withObject "DeprecationRecord" $ \obj -> do
|
||||
package <- PackageName <$> (obj .: "deprecated-package")
|
||||
inFavourOf <- map PackageName <$> (obj .: "in-favour-of")
|
||||
return $ DeprecationRecord package inFavourOf
|
||||
where
|
||||
parsePackageName name = return (PackageName name)
|
||||
parsePackageName = fmap PackageName
|
||||
|
||||
toDeprecated :: DeprecationRecord -> Deprecated
|
||||
toDeprecated (DeprecationRecord deprecated _) = Deprecated deprecated
|
||||
@ -47,3 +47,14 @@ toSuggestions (DeprecationRecord deprecated inFavourOf) =
|
||||
suggestedPackage = favoured,
|
||||
suggestedInsteadOf = deprecated
|
||||
}
|
||||
|
||||
loadDeprecationInfo ::
|
||||
( HasHttpManager env
|
||||
, MonadReader env m
|
||||
, MonadThrow m
|
||||
, MonadIO m)
|
||||
=> m (Either String HackageDeprecationInfo)
|
||||
loadDeprecationInfo = do
|
||||
req <- parseUrl "http://hackage.haskell.org/packages/deprecated.json"
|
||||
res <- httpLbs req
|
||||
return $! Aeson.eitherDecode (responseBody res)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user