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

8
src/ATrade/MDS/Database.hs

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

16
src/ATrade/MDS/HistoryServer.hs

@ -1,14 +1,26 @@ @@ -1,14 +1,26 @@
module ATrade.MDS.HistoryServer (
startHistoryServer,
stopHistoryServer
) where
import System.ZMQ4
import ATrade.MDS.Database
import Control.Concurrent
data HistoryServer = HistoryServer ThreadId
}
data HistoryServer = HistoryServer (MVar ()) (MVar ()) ThreadId
startHistoryServer :: DatabaseInterface -> Context -> IO HistoryServer
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