From a98af0185c18e9018c44693fecc4b547f92d9307 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 24 Oct 2023 20:05:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AD=E3=82=B0=E3=81=AEMDC=E3=82=92?= =?UTF-8?q?kotlinx.coroutine=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 1 + .../kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt | 5 +++-- .../dev/usbharu/hideout/service/core/ExposedTransaction.kt | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) 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() } }