on master help sign in
autoflush
commita3dbdb8b5b94808cce6268cc57ca40ea736a6292 authorAleksey Uimanov <s9gf4ult@gmail.com> dateThu 11 Jul 2019, 12:47 (7 years ago) parent143ee56
2 files changed+12−3
katip/katip.cabal+1 katip/src/Katip/Scribes/RotatingHandler.hs+11−3
katip/katip.cabal+1
@@ -51,6 +51,7 @@ library
5151 , OverloadedStrings
5252 , RankNTypes
5353 , RecordWildCards
54+ , ScopedTypeVariables
5455 , TemplateHaskell
5556
5657 build-depends: base >=4.9.0.0 && <5
katip/src/Katip/Scribes/RotatingHandler.hs+11−3
@@ -1,6 +1,7 @@
11module Katip.Scribes.RotatingHandler where
22
33import Control.Applicative
4+import Control.Concurrent
45import Control.Concurrent.Async
56import Control.Concurrent.STM
67import Control.Debounce
@@ -65,7 +66,7 @@ newFileOwner fp s = do
6566 <|> (Right <$> readAllData)
6667 debounce action = case fosDebounceFreq s of
6768 Nothing -> do
68− return action
69+ return $ return ()
6970 Just freq -> mkDebounce $ defaultDebounceSettings
7071 { debounceAction = action
7172 , debounceFreq = freq }
@@ -75,7 +76,7 @@ newFileOwner fp s = do
7576 Right bs -> do
7677 h <- readIORef ref
7778 BL.hPutStr h $ mconcat bs
78− flush
79+ flush -- auto debounced flush
7980 recur
8081 Left c -> case c of
8182 CloseMsg -> return () -- release will close the handler
@@ -90,7 +91,14 @@ newFileOwner fp s = do
9091 recur
9192 recur
9293 worker :: IO ()
93− worker = bracket ack release go
94+ worker = try (bracket ack release go) >>= \case
95+ Left (_ :: SomeException) -> do
96+ threadDelay 100000
97+ -- to not restart the worker function too often
98+ worker
99+ -- We dont want the worker thread become unavailable because
100+ -- of exceptions. E.g. could not create or write the file.
101+ Right () -> return ()
94102 asyncRet <- async worker
95103 return $ FileOwner
96104 { foDataQueune = dqueue