Browse Source

Broker client: debug logging

master
Denis Tereshkin 9 years ago
parent
commit
c84926e8ba
  1. 25
      src/ATrade/Broker/Client.hs

25
src/ATrade/Broker/Client.hs

@ -44,17 +44,20 @@ brokerClientThread :: Context -> T.Text -> MVar BrokerServerRequest -> MVar Brok
brokerClientThread ctx ep cmd resp comp killMv = finally brokerClientThread' cleanup brokerClientThread ctx ep cmd resp comp killMv = finally brokerClientThread' cleanup
where where
cleanup = putMVar comp () cleanup = putMVar comp ()
brokerClientThread' = whileM_ (isNothing <$> tryReadMVar killMv) $ withSocket ctx Req (\sock -> do brokerClientThread' = whileM_ (isNothing <$> tryReadMVar killMv) $ handle
connect sock $ T.unpack ep (\e -> do
whileM_ (isNothing <$> tryReadMVar killMv) $ do warningM "Strategy" $ "Broker client: exception: " ++ show (e :: SomeException)
request <- takeMVar cmd throwIO e) $ withSocket ctx Req (\sock -> do
send sock [] (BL.toStrict $ encode request) connect sock $ T.unpack ep
incomingMessage <- timeout 1000000 $ receive sock whileM_ (isNothing <$> tryReadMVar killMv) $ do
case incomingMessage of request <- takeMVar cmd
Just msg -> case decode . BL.fromStrict $ msg of send sock [] (BL.toStrict $ encode request)
Just response -> putMVar resp response incomingMessage <- timeout 1000000 $ receive sock
Nothing -> putMVar resp (ResponseError "Unable to decode response") case incomingMessage of
Nothing -> putMVar resp (ResponseError "Response timeout")) Just msg -> case decode . BL.fromStrict $ msg of
Just response -> putMVar resp response
Nothing -> putMVar resp (ResponseError "Unable to decode response")
Nothing -> putMVar resp (ResponseError "Response timeout"))
startBrokerClient :: Context -> T.Text -> IO BrokerClientHandle startBrokerClient :: Context -> T.Text -> IO BrokerClientHandle
startBrokerClient ctx endpoint = do startBrokerClient ctx endpoint = do

Loading…
Cancel
Save