Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: log when the file is reloaded #1099

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading