Merge pull request #130 from usbharu/feature/mongodb-url

feat: mongodbのurlを変更可能に
This commit is contained in:
usbharu 2023-11-02 18:25:17 +09:00 committed by GitHub
commit 38b34b0424
3 changed files with 15 additions and 4 deletions

View File

@ -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")

View File

@ -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()
}
}

View File

@ -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 <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit) {
kjob.schedule(job, block)
}
override fun close() {
kjob.shutdown()
}
}