1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 00:33:59 +03:00

Pass Messages over the queue with the current time.

This commit is contained in:
Rob Rix 2017-07-23 14:12:13 -04:00
parent 29fd11f96f
commit 69b9b1d6be
2 changed files with 7 additions and 2 deletions

View File

@ -114,6 +114,7 @@ library
, template-haskell , template-haskell
, text >= 1.2.1.3 , text >= 1.2.1.3
, these , these
, time
, haskell-tree-sitter , haskell-tree-sitter
, c , c
, go , go

View File

@ -36,6 +36,8 @@ import Data.String
import qualified Data.Syntax as Syntax import qualified Data.Syntax as Syntax
import Data.Syntax.Algebra (RAlgebra, decoratorWithAlgebra) import Data.Syntax.Algebra (RAlgebra, decoratorWithAlgebra)
import qualified Data.Syntax.Assignment as Assignment import qualified Data.Syntax.Assignment as Assignment
import qualified Data.Time.Clock as Time
import qualified Data.Time.Clock.POSIX as Time (getCurrentTime)
import Data.Union import Data.Union
import Diff import Diff
import qualified Files import qualified Files
@ -181,7 +183,9 @@ runTaskWithOptions options task = do
ReadBlobPairs source -> pure <$ writeLog Info "ReadBlobPairs" <*> either Files.readBlobPairsFromHandle (traverse (traverse (uncurry Files.readFile))) source ReadBlobPairs source -> pure <$ writeLog Info "ReadBlobPairs" <*> either Files.readBlobPairsFromHandle (traverse (traverse (uncurry Files.readFile))) source
WriteToOutput destination contents -> pure <$ writeLog Info "WriteToOutput" <*> liftIO (either B.hPutStr B.writeFile destination contents) WriteToOutput destination contents -> pure <$ writeLog Info "WriteToOutput" <*> liftIO (either B.hPutStr B.writeFile destination contents)
WriteLog level message WriteLog level message
| Just logLevel <- optionsLevel options, level <= logLevel -> pure <$> liftIO (atomically (writeTMQueue logQueue (level, message))) | Just logLevel <- optionsLevel options, level <= logLevel -> pure <$> liftIO (do
now <- Time.getCurrentTime
atomically (writeTMQueue logQueue (Message now level message)))
| otherwise -> pure (pure ()) | otherwise -> pure (pure ())
Parse parser blob -> pure <$ writeLog Info "Parse" <*> runParser options parser blob Parse parser blob -> pure <$ writeLog Info "Parse" <*> runParser options parser blob
Decorate algebra term -> pure <$ writeLog Info "Decorate" <*> pure (decoratorWithAlgebra algebra term) Decorate algebra term -> pure <$ writeLog Info "Decorate" <*> pure (decoratorWithAlgebra algebra term)
@ -196,7 +200,7 @@ runTaskWithOptions options task = do
where logSink options queue = do where logSink options queue = do
message <- atomically (readTMQueue queue) message <- atomically (readTMQueue queue)
case message of case message of
Just (level, message) -> do Just (Message _ level message) -> do
hPutStr stderr (formatMessage (fromMaybe True (optionsColour options)) level message) hPutStr stderr (formatMessage (fromMaybe True (optionsColour options)) level message)
logSink options queue logSink options queue
_ -> pure () _ -> pure ()