Skip to content

Commit

Permalink
config: log when the file is reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Jan 5, 2024
1 parent 2ba9fdd commit 4704e75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Monocle/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/Monocle/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions src/Monocle/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

------------------------------------------------------------------
--
Expand Down

0 comments on commit 4704e75

Please sign in to comment.