diff --git a/build.gradle.kts b/build.gradle.kts index 0269b222..34f81ca1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 26a6306b..9f4f87e2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -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 { - return CoroutineScope(Dispatchers.IO).async { - newSuspendedTransaction { + return CoroutineScope(Dispatchers.IO + MDCContext()).async { + newSuspendedTransaction(MDCContext()) { fetchNote(url, targetActor) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt b/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt index bcd95261..f0ed0568 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt @@ -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 transaction(block: suspend () -> T): T { - return newSuspendedTransaction { + return newSuspendedTransaction(MDCContext()) { block() } } override suspend fun transaction(transactionLevel: Int, block: suspend () -> T): T { - return newSuspendedTransaction(transactionIsolation = transactionLevel) { + return newSuspendedTransaction(MDCContext(), transactionIsolation = transactionLevel) { block() } }