mirror of
https://github.com/aelve/guide.git
synced 2024-12-25 13:51:45 +03:00
Kill the EKG server thread upon exit
This commit is contained in:
parent
1209b2dfa2
commit
46ace5f57a
16
src/Main.hs
16
src/Main.hs
@ -256,8 +256,17 @@ otherMethods = do
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
bracket (openLocalStateFrom "state/" sampleState)
|
||||
(\db -> createCheckpoint db >> closeAcidState db) $ \db -> do
|
||||
-- When we run in GHCi and we exit the main thread, the EKG thread (that
|
||||
-- runs the localhost:5050 server which provides statistics) may keep
|
||||
-- running. This makes running this in GHCi annoying, because you have to
|
||||
-- restart GHCi before every run. So, we kill the thread in the finaliser.
|
||||
ekgId <- newIORef Nothing
|
||||
let prepare = openLocalStateFrom "state/" sampleState
|
||||
finalise db = do
|
||||
createCheckpoint db
|
||||
closeAcidState db
|
||||
mapM_ killThread =<< readIORef ekgId
|
||||
bracket prepare finalise $ \db -> do
|
||||
-- Create a checkpoint every hour. Note: if nothing was changed,
|
||||
-- acid-state overwrites the previous checkpoint, which saves us some
|
||||
-- space.
|
||||
@ -265,9 +274,8 @@ main = do
|
||||
createCheckpoint db
|
||||
threadDelay (1000000 * 3600)
|
||||
-- EKG metrics
|
||||
-- TODO: stop the server upon exit, somehow (or just don't start it
|
||||
-- unless there's been some option passed?)
|
||||
ekg <- EKG.forkServer "localhost" 5050
|
||||
writeIORef ekgId (Just (EKG.serverThreadId ekg))
|
||||
waiMetrics <- EKG.registerWaiMetrics (EKG.serverMetricStore ekg)
|
||||
categoryGauge <- EKG.getGauge "db.categories" ekg
|
||||
itemGauge <- EKG.getGauge "db.items" ekg
|
||||
|
Loading…
Reference in New Issue
Block a user