Skip to content

Commit

Permalink
Create DB connection is try/catch block (#128)
Browse files Browse the repository at this point in the history
* Create DB connection is try/catch block

* increase version

* use inserted_at instead of occurred_at for warmup/check (due to index
  • Loading branch information
kgribov committed Apr 15, 2024
1 parent e05d1dd commit 8d682a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/CI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.lang.Boolean.parseBoolean
object Ci {

private const val SNAPSHOT_BASE = "0.7.0"
private const val RELEASE_VERSION = "0.6.6"
private const val RELEASE_VERSION = "0.6.7"
private val githubSha = System.getenv("GITHUB_SHA") ?: "latest"

val publishRelease = System.getProperty("release", "true").let(::parseBoolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ abstract class TransactionManager<C>(
open suspend fun <R> withConnection(block: suspend (C) -> R): R {
return when (val existingConn = ctxConnection()) {
null -> {
val newConn = connectionProvider(coroutineContext).acquire()
var newConn: C? = null
try {
newConn = connectionProvider(coroutineContext).acquire()
block(newConn)
} finally {
connectionProvider(coroutineContext).release(newConn)
newConn?.let { connectionProvider(coroutineContext).release(it) }
}
}
else -> block(existingConn)
Expand All @@ -39,8 +40,9 @@ abstract class TransactionManager<C>(
checkCtxConnectionMode(mode)
return when (val existingConn = ctxConnection()) {
null -> {
val newConn = primaryProvider.acquire()
var newConn: C? = null
try {
newConn = primaryProvider.acquire()
val ctx = wrapConnection(newConn)
withContext(ctx) {
try {
Expand All @@ -54,7 +56,7 @@ abstract class TransactionManager<C>(
}
}
} finally {
primaryProvider.release(newConn)
newConn?.let { primaryProvider.release(it) }
}
}
// we do not commit/rollback/release existingConn after calling block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class JooqEventRepository(
modelEvent = FakeModelEvent
)
val select = dslContext.selectFrom(MODEL_EVENTS)
.orderBy(MODEL_EVENTS.OCCURRED_AT.desc())
.orderBy(MODEL_EVENTS.INSERTED_AT.desc())
.limit(1)
queryExecutor.executeSelect(
dslContext = dslContext,
Expand Down

0 comments on commit 8d682a6

Please sign in to comment.