fix: ジョブキューの修正 ログの追加

This commit is contained in:
usbharu 2023-12-03 10:28:44 +09:00
parent 158cd3a6df
commit 0d5fecbd4d
3 changed files with 25 additions and 1 deletions

View File

@ -32,7 +32,10 @@ class KJobJobQueueParentService : JobQueueParentService {
} }
override suspend fun <T, J : HideoutJob<T, J>> scheduleTypeSafe(job: J, jobProps: T) { override suspend fun <T, J : HideoutJob<T, J>> scheduleTypeSafe(job: J, jobProps: T) {
logger.debug("SCHEDULE Job: {}", job.name)
logger.trace("Job props: {}", jobProps)
val convert: ScheduleContext<J>.(J) -> Unit = job.convert(jobProps) val convert: ScheduleContext<J>.(J) -> Unit = job.convert(jobProps)
kjob.schedule(job, convert) kjob.schedule(job, convert)
logger.debug("SUCCESS Schedule Job: {}", job.name)
} }
} }

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.infrastructure.kjobmongodb
import com.mongodb.reactivestreams.client.MongoClient import com.mongodb.reactivestreams.client.MongoClient
import dev.usbharu.hideout.core.external.job.HideoutJob import dev.usbharu.hideout.core.external.job.HideoutJob
import dev.usbharu.hideout.core.service.job.JobProcessor
import dev.usbharu.hideout.core.service.job.JobQueueWorkerService import dev.usbharu.hideout.core.service.job.JobQueueWorkerService
import kjob.core.dsl.JobContextWithProps import kjob.core.dsl.JobContextWithProps
import kjob.core.dsl.JobRegisterContext import kjob.core.dsl.JobRegisterContext
@ -13,7 +14,10 @@ import org.springframework.stereotype.Service
@Service @Service
@ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false) @ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false)
class KJobMongoJobQueueWorkerService(private val mongoClient: MongoClient) : JobQueueWorkerService, AutoCloseable { class KJobMongoJobQueueWorkerService(
private val mongoClient: MongoClient,
private val jobQueueProcessorList: List<JobProcessor<*, *>>
) : JobQueueWorkerService, AutoCloseable {
val kjob by lazy { val kjob by lazy {
kjob(Mongo) { kjob(Mongo) {
client = mongoClient client = mongoClient
@ -30,6 +34,14 @@ class KJobMongoJobQueueWorkerService(private val mongoClient: MongoClient) : Job
defines.forEach { job -> defines.forEach { job ->
kjob.register(job.first, job.second) kjob.register(job.first, job.second)
} }
for (jobProcessor in jobQueueProcessorList) {
kjob.register(jobProcessor.job()) {
execute {
val param = it.convertUnsafe(props)
jobProcessor.process(param)
}
}
}
} }
override fun close() { override fun close() {

View File

@ -7,6 +7,7 @@ import kjob.core.Job
import kjob.core.dsl.ScheduleContext import kjob.core.dsl.ScheduleContext
import kjob.core.kjob import kjob.core.kjob
import kjob.mongo.Mongo import kjob.mongo.Mongo
import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@ -26,15 +27,23 @@ class KjobMongoJobQueueParentService(private val mongoClient: MongoClient) : Job
@Deprecated("use type safe → scheduleTypeSafe") @Deprecated("use type safe → scheduleTypeSafe")
override suspend fun <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit) { override suspend fun <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit) {
logger.debug("SCHEDULE Job: {}", job.name)
kjob.schedule(job, block) kjob.schedule(job, block)
} }
override suspend fun <T, J : HideoutJob<T, J>> scheduleTypeSafe(job: J, jobProps: T) { override suspend fun <T, J : HideoutJob<T, J>> scheduleTypeSafe(job: J, jobProps: T) {
logger.debug("SCHEDULE Job: {}", job.name)
logger.trace("Job props: {}", jobProps)
val convert = job.convert(jobProps) val convert = job.convert(jobProps)
kjob.schedule(job, convert) kjob.schedule(job, convert)
logger.debug("SUCCESS Job: {}", job.name)
} }
override fun close() { override fun close() {
kjob.shutdown() kjob.shutdown()
} }
companion object {
private val logger = LoggerFactory.getLogger(KjobMongoJobQueueParentService::class.java)
}
} }