From 4704e75d0b96e1953d44a791f4022de1e86c0e9a Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Fri, 5 Jan 2024 16:11:28 +0000 Subject: [PATCH] config: log when the file is reloaded --- src/Monocle/Api/Server.hs | 2 +- src/Monocle/Config.hs | 2 -- src/Monocle/Effects.hs | 11 +++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Monocle/Api/Server.hs b/src/Monocle/Api/Server.hs index 0df45b4c5..0e5169eb7 100644 --- a/src/Monocle/Api/Server.hs +++ b/src/Monocle/Api/Server.hs @@ -77,7 +77,7 @@ import Servant.Auth.Server.Internal.JWT (makeJWT) import Web.Cookie (SetCookie (..), defaultSetCookie, sameSiteStrict) -- | 'getWorkspaces' returns the list of workspace, reloading the config when the file changed. -getWorkspaces :: MonoConfigEffect :> es => Eff es [Config.Index] +getWorkspaces :: (LoggerEffect :> es, MonoConfigEffect :> es) => Eff es [Config.Index] getWorkspaces = Config.workspaces . Config.csConfig <$> getReloadConfig -- | 'updateIndex' if needed - ensures index exists and refresh crawler Metadata diff --git a/src/Monocle/Config.hs b/src/Monocle/Config.hs index d45110051..6e7484341 100644 --- a/src/Monocle/Config.hs +++ b/src/Monocle/Config.hs @@ -244,8 +244,6 @@ reloadConfig fp = do configTS <- getModificationTime fp if configTS > prevConfigTS then do - -- TODO: use log reload event - putTextLn $ from fp <> ": reloading config" config <- loadConfig fp modifyMVar_ wsRef (const . pure $ mkWorkspaceStatus config) pure ((configTS, config), ConfigStatus True config wsRef) diff --git a/src/Monocle/Effects.hs b/src/Monocle/Effects.hs index 07ac408ba..43fb30667 100644 --- a/src/Monocle/Effects.hs +++ b/src/Monocle/Effects.hs @@ -136,11 +136,11 @@ testTree = hClose fd writeFile path "workspaces: []" setEnv "CRAWLERS_API_KEY" "42" - runEff (runMonoConfig path $ testMonoConfig path) `finally` removeFile path + runEff (runLoggerEffect $ runMonoConfig path $ testMonoConfig path) `finally` removeFile path ] where testEff a b = liftIO (a @?= b) - testMonoConfig :: (MonoConfigEffect :> es, IOE :> es) => FilePath -> Eff es () + testMonoConfig :: (LoggerEffect :> es, MonoConfigEffect :> es, IOE :> es) => FilePath -> Eff es () testMonoConfig fp = do -- Setup the test config let getNames c = Monocle.Config.getWorkspaceName <$> Monocle.Config.getWorkspaces (Monocle.Config.csConfig c) @@ -189,10 +189,13 @@ runMonoConfigFromEnv :: IOE :> es => IO ConfigStatus -> Eff (MonoConfigEffect : runMonoConfigFromEnv reload = evalStaticRep (MonoConfigEffect reload) -- | The lifted version of Monocle.Config.reloadConfig -getReloadConfig :: MonoConfigEffect :> es => Eff es ConfigStatus +getReloadConfig :: (LoggerEffect :> es, MonoConfigEffect :> es) => Eff es ConfigStatus getReloadConfig = do MonoConfigEffect reload <- getStaticRep - unsafeEff_ reload + cs <- unsafeEff_ reload + when cs.csReloaded do + logInfo "Config reloaded" ["workspaces" .= length cs.csConfig.workspaces] + pure cs ------------------------------------------------------------------ --