1
0
Fork 0

Prep work for using a configuration file

main
Kevin Belisle 2021-06-30 15:24:34 -04:00
parent d5ea7cac45
commit a4140f708c
1 changed files with 23 additions and 12 deletions

View File

@ -14,34 +14,48 @@ fun main() =
runBlocking { runBlocking {
println("Starting Stonks...") println("Starting Stonks...")
val databaseBaseDir = "./databases"
val databaseName = "statistics"
val h2StartWebServer = true val h2StartWebServer = true
val h2tWebServerPort = 8082 val h2tWebServerPort = 8082
val h2TcpServerPort = 9092 val h2TcpServerPort = 9092
val database = initH2Server(h2TcpServerPort, h2StartWebServer, h2tWebServerPort) val database =
initH2Server(
databaseBaseDir,
databaseName,
h2TcpServerPort,
h2StartWebServer,
h2tWebServerPort)
val apiServerPort = 7000 val apiServerPort = 7000
initApiServer(apiServerPort, database) initApiServer(apiServerPort, database)
val periodicFetchingInterval = 15 * 60 * 1000L val periodicFetchingInterval = 15 * 60 * 1000L
val statisticsFolder = "../test_data" val minecraftStatsFolder = "../test_data"
initPeriodicFetching(periodicFetchingInterval, statisticsFolder, database) initPeriodicFetching(periodicFetchingInterval, minecraftStatsFolder, database)
delay(60 * 1000L) delay(60 * 1000L)
println("END") println("END")
} }
fun initH2Server(h2TcpServerPort: Int, h2StartWebServer: Boolean, h2WebServerPort: Int): Database { fun initH2Server(
databaseBaseDir: String,
databaseName: String,
h2TcpServerPort: Int,
h2StartWebServer: Boolean,
h2WebServerPort: Int
): Database {
val webServer = val webServer =
Server.createWebServer( Server.createWebServer(
"-trace", "-baseDir", "./databases", "-webPort", h2WebServerPort.toString()) "-trace", "-baseDir", databaseBaseDir, "-webPort", h2WebServerPort.toString())
val tcpServer = val tcpServer =
Server.createTcpServer( Server.createTcpServer(
"-trace", "-baseDir", "./databases", "-webPort", h2TcpServerPort.toString()) "-trace", "-baseDir", databaseBaseDir, "-webPort", h2TcpServerPort.toString())
if (h2StartWebServer) { if (h2StartWebServer) {
webServer.start() webServer.start()
@ -51,17 +65,14 @@ fun initH2Server(h2TcpServerPort: Int, h2StartWebServer: Boolean, h2WebServerPor
tcpServer.start() tcpServer.start()
println("H2 TCP endpoint started: ${tcpServer.getURL()}") println("H2 TCP endpoint started: ${tcpServer.getURL()}")
val database = Database.connect("jdbc:h2:./databases/test", "org.h2.Driver") val database = Database.connect("jdbc:h2:$databaseBaseDir/$databaseName", "org.h2.Driver")
Statistics.index(false, Statistics.playerId)
Statistics.index("idx_type_name", false, Statistics.type, Statistics.name)
Statistics.index("idx_timestamp", false, Statistics.timestamp)
Statistics.index("idx_value", false, Statistics.value)
transaction { transaction {
addLogger(StdOutSqlLogger) addLogger(StdOutSqlLogger)
SchemaUtils.create(Statistics) SchemaUtils.create(Statistics)
// Create indexes with explicit SQL because I can't figure out how to do it with exposed
// Wrap it in a try block because it throws an exception if index already exists
try { try {
TransactionManager.current() TransactionManager.current()
.exec("CREATE INDEX idx_playerid ON Statistics (\"PlayerId\")") .exec("CREATE INDEX idx_playerid ON Statistics (\"PlayerId\")")