diff --git a/build.gradle.kts b/build.gradle.kts index 62de2087..47ebb8b3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -132,6 +132,7 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.springframework.security:spring-security-oauth2-jose") implementation("org.springframework.boot:spring-boot-starter-data-mongodb") + implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") implementation("org.jetbrains.exposed:exposed-spring-boot-starter:0.44.0") implementation("io.trbl:blurhash:1.0.0") implementation("software.amazon.awssdk:s3:2.20.157") diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt index 01b57659..5d4ed22c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.infrastructure.kjobmongodb +import com.mongodb.reactivestreams.client.MongoClient import dev.usbharu.hideout.core.service.job.JobQueueWorkerService import kjob.core.dsl.JobRegisterContext import kjob.core.dsl.KJobFunctions @@ -12,10 +13,10 @@ import kjob.core.dsl.JobContextWithProps as JCWP @Service @ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false) -class KJobMongoJobQueueWorkerService : JobQueueWorkerService { +class KJobMongoJobQueueWorkerService(private val mongoClient: MongoClient) : JobQueueWorkerService, AutoCloseable { val kjob by lazy { kjob(Mongo) { - connectionString = "mongodb://localhost" + client = mongoClient nonBlockingMaxJobs = 10 blockingMaxJobs = 10 jobExecutionPeriodInSeconds = 1 @@ -29,4 +30,8 @@ class KJobMongoJobQueueWorkerService : JobQueueWorkerService { kjob.register(job.first, job.second) } } + + override fun close() { + kjob.shutdown() + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KjobMongoJobQueueParentService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KjobMongoJobQueueParentService.kt index 40ad8cdf..0875325d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KjobMongoJobQueueParentService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KjobMongoJobQueueParentService.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.infrastructure.kjobmongodb +import com.mongodb.reactivestreams.client.MongoClient import dev.usbharu.hideout.core.service.job.JobQueueParentService import kjob.core.Job import kjob.core.dsl.ScheduleContext @@ -10,9 +11,9 @@ import org.springframework.stereotype.Service @Service @ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false) -class KjobMongoJobQueueParentService : JobQueueParentService { +class KjobMongoJobQueueParentService(private val mongoClient: MongoClient) : JobQueueParentService, AutoCloseable { private val kjob = kjob(Mongo) { - connectionString = "mongodb://localhost" + client = mongoClient databaseName = "kjob" jobCollection = "kjob-jobs" lockCollection = "kjob-locks" @@ -25,4 +26,8 @@ class KjobMongoJobQueueParentService : JobQueueParentService { override suspend fun schedule(job: J, block: ScheduleContext.(J) -> Unit) { kjob.schedule(job, block) } + + override fun close() { + kjob.shutdown() + } }