Browse Source

More logging

master
Denis Tereshkin 6 years ago
parent
commit
d604f19fb4
  1. 10
      app/Main.hs
  2. 4
      mds.conf
  3. 3
      src/ATrade/MDS/Database.hs

10
app/Main.hs

@ -11,7 +11,6 @@ import ATrade.MDS.HistoryServer @@ -11,7 +11,6 @@ import ATrade.MDS.HistoryServer
import Control.Concurrent
import Control.Monad
import System.IO
import System.Log.Formatter
import System.Log.Handler (setFormatter)
import System.Log.Handler.Simple
@ -44,7 +43,6 @@ initLogging = do @@ -44,7 +43,6 @@ initLogging = do
(\x -> return $
setFormatter x (simpleLogFormatter "$utcTime\t {$loggername} <$prio> -> $msg"))
hSetBuffering stderr LineBuffering
updateGlobalLogger rootLoggerName (setLevel DEBUG)
updateGlobalLogger rootLoggerName (setHandlers [handler])
@ -58,22 +56,22 @@ getConfig = do @@ -58,22 +56,22 @@ getConfig = do
main :: IO ()
main = do
initLogging
debugM "main" "Initializing MDS"
infoM "main" "Initializing MDS"
cfg <- getConfig
debugM "main" "Config OK"
infoM "main" "Config OK"
let dbConfig = DatabaseConfig { dbPath = cfgDbPath cfg,
dbDatabase = cfgDbName cfg,
dbUser = cfgDbAccount cfg,
dbPassword = cfgDbPassword cfg }
db <- initDatabase dbConfig
debugM "main" "DB initialized"
infoM "main" "DB initialized"
let hsConfig = HistoryServerConfig {
hspQHPEndpoint = cfgQHPEndpoint cfg,
hspHAPEndpoint = cfgHAPEndpoint cfg }
debugM "main" "Starting history server"
infoM "main" "Starting history server"
withContext $ \ctx -> do
_ <- startHistoryServer hsConfig db ctx
forever $ threadDelay 1000000

4
mds.conf

@ -3,6 +3,6 @@ @@ -3,6 +3,6 @@
"name" : "",
"account" : "",
"password" : "",
"qhp_endpoint" : "tcp://0.0.0.0:5595",
"hap_endpoint" : "tcp://0.0.0.0:5605"
"qhp_endpoint" : "tcp://0.0.0.0:5550",
"hap_endpoint" : "tcp://0.0.0.0:5551"
}

3
src/ATrade/MDS/Database.hs

@ -23,6 +23,7 @@ import Data.Time.Clock.POSIX @@ -23,6 +23,7 @@ import Data.Time.Clock.POSIX
import qualified Data.Vector as V
import Database.HDBC
import Database.HDBC.Sqlite3
import System.Log.Logger
data TimeInterval = TimeInterval UTCTime UTCTime
@ -48,8 +49,10 @@ type MdsHandle = Connection @@ -48,8 +49,10 @@ type MdsHandle = Connection
initDatabase :: DatabaseConfig -> IO MdsHandle
initDatabase config = do
infoM "DB" $ "Initializing DB"
conn <- connectSqlite3 (T.unpack $ dbPath config)
makeSchema conn
infoM "DB" $ "Schema updated"
return conn
where
makeSchema conn = runRaw conn "CREATE TABLE IF NOT EXISTS bars (id SERIAL PRIMARY KEY, ticker TEXT, timestamp BIGINT, timeframe INTEGER, open NUMERIC(20, 10), high NUMERIC(20, 10), low NUMERIC(20, 10), close NUMERIC(20,10), volume BIGINT);"

Loading…
Cancel
Save