mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-21 16:31:56 +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 Control.Monad.Logger (runLoggingT, LoggingT, defaultLogStr)
|
||||||
import Data.BlobStore (fileStore, storeWrite, cachedS3Store)
|
import Data.BlobStore (fileStore, storeWrite, cachedS3Store)
|
||||||
import Data.Hackage
|
import Data.Hackage
|
||||||
|
import Data.Hackage.DeprecationInfo
|
||||||
import Data.Unpacking (newDocUnpacker, createHoogleDatabases)
|
import Data.Unpacking (newDocUnpacker, createHoogleDatabases)
|
||||||
import Data.WebsiteContent
|
import Data.WebsiteContent
|
||||||
import Data.Slug (SnapSlug (..), safeMakeSlug, HasGenIO)
|
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
|
let runDB' :: SqlPersistT (ResourceT (ReaderT env (LoggingT IO))) a
|
||||||
-> ReaderT env (LoggingT IO) a
|
-> ReaderT env (LoggingT IO) a
|
||||||
runDB' = runResourceT . flip (Database.Persist.runPool dbconf) p
|
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
|
uploadHistory0 <- runDB' $ selectSource [] [] $$ sinkUploadHistory
|
||||||
let toMDPair (E.Value name, E.Value version, E.Value hash') =
|
let toMDPair (E.Value name, E.Value version, E.Value hash') =
|
||||||
(name, (version, hash'))
|
(name, (version, hash'))
|
||||||
@ -320,6 +332,7 @@ appLoadCabalFiles updateDB forceUpdate env dbconf p = do
|
|||||||
deleteWhere [DependencyUser ==. metadataName md]
|
deleteWhere [DependencyUser ==. metadataName md]
|
||||||
insertMany_ $ flip map (metadataDeps md) $ \dep ->
|
insertMany_ $ flip map (metadataDeps md) $ \dep ->
|
||||||
Dependency (PackageName dep) (metadataName md)
|
Dependency (PackageName dep) (metadataName md)
|
||||||
|
|
||||||
case eres of
|
case eres of
|
||||||
Left e -> $logError $ tshow e
|
Left e -> $logError $ tshow e
|
||||||
Right () -> return ()
|
Right () -> return ()
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
-- into model data to be stored in the database.
|
-- into model data to be stored in the database.
|
||||||
module Data.Hackage.DeprecationInfo
|
module Data.Hackage.DeprecationInfo
|
||||||
( HackageDeprecationInfo(..)
|
( HackageDeprecationInfo(..)
|
||||||
|
, loadDeprecationInfo
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude
|
import ClassyPrelude.Yesod
|
||||||
import Data.Aeson
|
import Data.Aeson as Aeson
|
||||||
import Model
|
import Model
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
@ -28,13 +29,12 @@ data DeprecationRecord = DeprecationRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance FromJSON DeprecationRecord where
|
instance FromJSON DeprecationRecord where
|
||||||
parseJSON j = do
|
parseJSON = withObject "DeprecationRecord" $ \obj -> do
|
||||||
obj <- parseJSON j
|
package <- PackageName <$> (obj .: "deprecated-package")
|
||||||
package <- (obj .: "deprecated-package") >>= parsePackageName
|
inFavourOf <- map PackageName <$> (obj .: "in-favour-of")
|
||||||
inFavourOf <- (obj .: "in-favour-of") >>= mapM parsePackageName
|
|
||||||
return $ DeprecationRecord package inFavourOf
|
return $ DeprecationRecord package inFavourOf
|
||||||
where
|
where
|
||||||
parsePackageName name = return (PackageName name)
|
parsePackageName = fmap PackageName
|
||||||
|
|
||||||
toDeprecated :: DeprecationRecord -> Deprecated
|
toDeprecated :: DeprecationRecord -> Deprecated
|
||||||
toDeprecated (DeprecationRecord deprecated _) = Deprecated deprecated
|
toDeprecated (DeprecationRecord deprecated _) = Deprecated deprecated
|
||||||
@ -47,3 +47,14 @@ toSuggestions (DeprecationRecord deprecated inFavourOf) =
|
|||||||
suggestedPackage = favoured,
|
suggestedPackage = favoured,
|
||||||
suggestedInsteadOf = deprecated
|
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