mirror of https://github.com/usbharu/Hideout.git
feat: ログのMDCをkotlinx.coroutineに対応
This commit is contained in:
parent
63c15b35d1
commit
a98af0185c
|
@ -137,6 +137,7 @@ dependencies {
|
|||
implementation("software.amazon.awssdk:s3:2.20.157")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.7.3")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:1.7.3")
|
||||
implementation("dev.usbharu:http-signature:1.0.0")
|
||||
|
||||
implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
|
||||
|
|
|
@ -29,6 +29,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.slf4j.MDCContext
|
||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
|
@ -43,8 +44,8 @@ interface APNoteService {
|
|||
|
||||
@Cacheable("fetchNote")
|
||||
fun fetchNoteAsync(url: String, targetActor: String? = null): Deferred<Note> {
|
||||
return CoroutineScope(Dispatchers.IO).async {
|
||||
newSuspendedTransaction {
|
||||
return CoroutineScope(Dispatchers.IO + MDCContext()).async {
|
||||
newSuspendedTransaction(MDCContext()) {
|
||||
fetchNote(url, targetActor)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package dev.usbharu.hideout.service.core
|
||||
|
||||
import kotlinx.coroutines.slf4j.MDCContext
|
||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class ExposedTransaction : Transaction {
|
||||
override suspend fun <T> transaction(block: suspend () -> T): T {
|
||||
return newSuspendedTransaction {
|
||||
return newSuspendedTransaction(MDCContext()) {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> transaction(transactionLevel: Int, block: suspend () -> T): T {
|
||||
return newSuspendedTransaction(transactionIsolation = transactionLevel) {
|
||||
return newSuspendedTransaction(MDCContext(), transactionIsolation = transactionLevel) {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue