Add brains-db config parameter

This commit is contained in:
Sergey Ivanov 2024-02-12 15:36:34 +04:00 committed by Dmitry Zuikov
parent cc7f2dd948
commit 69f612e5fc
2 changed files with 16 additions and 6 deletions

View File

@ -720,12 +720,18 @@ newBasicBrains :: forall e m . (Hashable (Peer e), MonadIO m)
-> m (BasicBrains e) -> m (BasicBrains e)
newBasicBrains cfg = liftIO do newBasicBrains cfg = liftIO do
stateDb <-
sdir <- peerStateDirDefault flip runReaderT cfg (cfgValue @PeerBrainsDBPath @(Maybe String))
>>= maybe
liftIO $ createDirectoryIfMissing True sdir ( do
sdir <- peerStateDirDefault
let stateDb = sdir </> "brains.db" liftIO $ createDirectoryIfMissing True sdir
pure $ sdir </> "brains.db"
)
( \p ->
p <$ do
liftIO $ createDirectoryIfMissing True (takeDirectory p)
)
brains <- runReaderT (cfgValue @PeerBrainsDb @(Maybe String)) cfg brains <- runReaderT (cfgValue @PeerBrainsDb @(Maybe String)) cfg
<&> fromMaybe ":memory:" <&> fromMaybe ":memory:"

View File

@ -39,6 +39,7 @@ data PeerDownloadLogKey
data PeerHttpPortKey data PeerHttpPortKey
data PeerTcpProbeWaitKey data PeerTcpProbeWaitKey
data PeerUseHttpDownload data PeerUseHttpDownload
data PeerBrainsDBPath
instance Monad m => HasConf (ReaderT PeerConfig m) where instance Monad m => HasConf (ReaderT PeerConfig m) where
getConf = asks (\(PeerConfig syn) -> syn) getConf = asks (\(PeerConfig syn) -> syn)
@ -55,6 +56,9 @@ instance Monad m => HasCfgKey PeerTcpProbeWaitKey (Maybe Integer) m where
instance Monad m => HasCfgKey PeerUseHttpDownload b m where instance Monad m => HasCfgKey PeerUseHttpDownload b m where
key = "http-download" key = "http-download"
instance Monad m => HasCfgKey PeerBrainsDBPath b m where
key = "brains-db"
instance Monad m => HasCfgKey PeerDownloadLogKey (Maybe String) m where instance Monad m => HasCfgKey PeerDownloadLogKey (Maybe String) m where
key = "download-log" key = "download-log"