Browse Source

More logging

master
Denis Tereshkin 6 years ago
parent
commit
e85211ccc0
  1. 9
      src/Bot.hs

9
src/Bot.hs

@ -37,6 +37,7 @@ import Text.Printf.TH
startBot :: Config -> IO () startBot :: Config -> IO ()
startBot conf = forever $ do startBot conf = forever $ do
killMVar <- newEmptyMVar killMVar <- newEmptyMVar
infoM "ATradeBot" "Starting session"
mbsess <- session mbsess <- session
(cHostname conf) (cHostname conf)
(Just ((\_ -> [scramSha1 (cUsername conf) Nothing (cPassword conf)]), Just "bot")) (Just ((\_ -> [scramSha1 (cUsername conf) Nothing (cPassword conf)]), Just "bot"))
@ -50,20 +51,24 @@ startBot conf = forever $ do
priceMapRef <- newIORef M.empty priceMapRef <- newIORef M.empty
tid2 <- forkIO $ quotesourceThread priceMapRef ctx tid2 <- forkIO $ quotesourceThread priceMapRef ctx
tid3 <- forkIO $ handleCommands sess priceMapRef tid3 <- forkIO $ handleCommands sess priceMapRef
infoM "ATradeBot" "Waiting for kill MVar"
(threadDelay 1000000) `untilM` (not <$> isEmptyMVar killMVar) (threadDelay 1000000) `untilM` (not <$> isEmptyMVar killMVar)
infoM "ATradeBot" "killMVar filled, killing child threads"
killThread tid1 killThread tid1
killThread tid2 killThread tid2
killThread tid3 killThread tid3
infoM "ATradeBot" "Threads killed"
where where
onConnectionClosed' killMVar sess _ = putMVar killMVar () onConnectionClosed' killMVar sess _ = do
infoM "ATradeBot" "Connection closed"
putMVar killMVar ()
threadSinkThread sess ctx = do threadSinkThread sess ctx = do
noticeM "ATradeBot.TradeSink" "Started trade sink thread" noticeM "ATradeBot.TradeSink" "Started trade sink thread"
withSocket ctx Rep $ \sock -> do withSocket ctx Rep $ \sock -> do
bind sock "tcp://0.0.0.0:5543" bind sock "tcp://0.0.0.0:5543"
forever $ do forever $ do
infoM "ATradeBot.TradeSink" "Waiting for incoming packet"
mTrade <- eitherDecode' . BL.fromStrict <$> receive sock mTrade <- eitherDecode' . BL.fromStrict <$> receive sock
send sock [] $ encodeUtf8 "{ \"response\" : \"ok\" }" send sock [] $ encodeUtf8 "{ \"response\" : \"ok\" }"
case mTrade of case mTrade of

Loading…
Cancel
Save