Browse Source

HistoryServer: start/stop

master
Denis Tereshkin 9 years ago
parent
commit
2862d8a626
  1. 1
      mds.cabal
  2. 8
      src/ATrade/MDS/Database.hs
  3. 16
      src/ATrade/MDS/HistoryServer.hs

1
mds.cabal

@ -16,6 +16,7 @@ cabal-version: >=1.10
library library
hs-source-dirs: src hs-source-dirs: src
exposed-modules: ATrade.MDS.Database exposed-modules: ATrade.MDS.Database
, ATrade.MDS.HistoryServer
build-depends: base >= 4.7 && < 5 build-depends: base >= 4.7 && < 5
, HDBC , HDBC
, HDBC-postgresql , HDBC-postgresql

8
src/ATrade/MDS/Database.hs

@ -121,10 +121,6 @@ doPutData cmdVar respVar tickerId timeInterval timeframe bars = do
resp <- takeMVar respVar resp <- takeMVar respVar
case resp of case resp of
DBOk -> return () DBOk -> return ()
DBError err -> do DBError err -> warningM "DB.Client" $ "Error while calling putData: " ++ show err
warningM "DB.Client" $ "Error while calling putData: " ++ show err _ -> warningM "DB.Client" "Unexpected response"
return ()
_ -> do
warningM "DB.Client" "Unexpected response"
return ()

16
src/ATrade/MDS/HistoryServer.hs

@ -1,14 +1,26 @@
module ATrade.MDS.HistoryServer ( module ATrade.MDS.HistoryServer (
startHistoryServer,
stopHistoryServer
) where ) where
import System.ZMQ4 import System.ZMQ4
import ATrade.MDS.Database import ATrade.MDS.Database
import Control.Concurrent import Control.Concurrent
data HistoryServer = HistoryServer ThreadId data HistoryServer = HistoryServer (MVar ()) (MVar ()) ThreadId
}
startHistoryServer :: DatabaseInterface -> Context -> IO HistoryServer startHistoryServer :: DatabaseInterface -> Context -> IO HistoryServer
startHistoryServer db ctx = do startHistoryServer db ctx = do
sock <- socket ctx Router
killMv <- newEmptyMVar
compMv <- newEmptyMVar
tid <- forkFinally (serverThread sock killMv compMv) (cleanup sock killMv compMv)
return $ HistoryServer killMv compMv tid
where
serverThread sock killMv compMv = undefined
cleanup sock killMv compMv = undefined
stopHistoryServer :: HistoryServer -> IO ()
stopHistoryServer (HistoryServer killMv compMv tid) = putMVar killMv () >> killThread tid >> readMVar compMv

Loading…
Cancel
Save