Compare commits

...

8 Commits

Author SHA1 Message Date
2ff712327f Update CHANGELOG.md 2022-09-09 04:22:56 +06:00
72e8e35e3f Update libs.versions.toml 2022-09-09 04:20:09 +06:00
030f9546f2 Update gradle.properties 2022-09-09 04:18:05 +06:00
1b3c479766 Merge pull request #44 from InsanusMokrassar/2.3.0
2.3.0
2022-09-04 16:10:09 +06:00
dcfb66ef6c fixes 2022-09-04 15:57:40 +06:00
763718716d improve reconnect feature 2022-09-04 15:07:30 +06:00
dfbc7be6f2 add option waitForConnection in database config 2022-09-04 14:37:44 +06:00
ab0578b312 start 2.3.0 2022-09-04 14:31:46 +06:00
6 changed files with 53 additions and 15 deletions

View File

@@ -1,5 +1,18 @@
# Changelog # Changelog
## 2.3.1
* `Versions`:
* `klock`: `3.1.0`
* `tgbotapi`: `3.2.1`
* `microutils`: `0.12.11`
* `ktor`: `2.1.1`
## 2.3.0
* `Bot`:
* Add option `reconnectOptions` in database config
## 2.2.0 ## 2.2.0
* `Versions`: * `Versions`:

View File

@@ -0,0 +1,9 @@
package dev.inmo.plagubot.config
import kotlinx.serialization.Serializable
@Serializable
data class DBConnectOptions(
val attempts: Int = 3,
val delay: Long = 1000L
)

View File

@@ -1,11 +1,15 @@
package dev.inmo.plagubot.config package dev.inmo.plagubot.config
import dev.inmo.kslog.common.e
import dev.inmo.kslog.common.logger
import kotlinx.coroutines.delay
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.transactions.transactionManager import org.jetbrains.exposed.sql.transactions.transactionManager
import org.koin.core.scope.Scope import org.koin.core.scope.Scope
import org.sqlite.JDBC import org.sqlite.JDBC
import java.lang.Exception
import java.sql.Connection import java.sql.Connection
inline val Scope.database: Database? inline val Scope.database: Database?
@@ -16,15 +20,24 @@ data class DatabaseConfig(
val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared", val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared",
val driver: String = JDBC::class.qualifiedName!!, val driver: String = JDBC::class.qualifiedName!!,
val username: String = "", val username: String = "",
val password: String = "" val password: String = "",
val reconnectOptions: DBConnectOptions? = DBConnectOptions()
) { ) {
@Transient @Transient
val database: Database = Database.connect( val database: Database = (0 until (reconnectOptions ?.attempts ?: 1)).firstNotNullOfOrNull {
url, runCatching {
driver, Database.connect(
username, url,
password driver,
).also { username,
it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED password
} ).also {
it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED
it.connector().close()
}
}.onFailure {
logger.e(it)
Thread.sleep(reconnectOptions ?.delay ?: return@onFailure)
}.getOrNull()
} ?: error("Unable to create database")
} }

View File

@@ -5,4 +5,4 @@ kotlin.js.generate.externals=true
kotlin.incremental=true kotlin.incremental=true
group=dev.inmo group=dev.inmo
version=2.2.0 version=2.3.1

View File

@@ -4,8 +4,8 @@ kt = "1.7.10"
kt-serialization = "1.4.0" kt-serialization = "1.4.0"
kt-coroutines = "1.6.4" kt-coroutines = "1.6.4"
microutils = "0.12.4" microutils = "0.12.11"
tgbotapi = "3.2.0" tgbotapi = "3.2.1"
kslog = "0.5.1" kslog = "0.5.1"
jb-exposed = "0.39.2" jb-exposed = "0.39.2"
@@ -13,10 +13,10 @@ jb-dokka = "1.7.10"
sqlite = "3.36.0.3" sqlite = "3.36.0.3"
klock = "3.0.0" klock = "3.1.0"
uuid = "0.5.0" uuid = "0.5.0"
ktor = "2.1.0" ktor = "2.1.1"
gh-release = "2.4.1" gh-release = "2.4.1"

View File

@@ -4,7 +4,10 @@
"driver": "org.sqlite.JDBC", "driver": "org.sqlite.JDBC",
"username": "OPTIONAL username", "username": "OPTIONAL username",
"password": "OPTIONAL password", "password": "OPTIONAL password",
"initAutomatically": false "reconnectOptions": {
"attempts": 3,
"delay": 1000
}
}, },
"botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678", "botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678",
"plugins": [ "plugins": [