feat: 型安全なジョブキューのプロセッサーを追加

This commit is contained in:
usbharu 2023-11-26 11:19:25 +09:00
parent dcac609b94
commit 1e8f49b554
3 changed files with 13 additions and 7 deletions

View File

@ -1,14 +1,14 @@
package dev.usbharu.hideout.core.infrastructure.kjobexposed package dev.usbharu.hideout.core.infrastructure.kjobexposed
import dev.usbharu.hideout.core.external.job.HideoutJob
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.JobRegisterContext import kjob.core.dsl.JobRegisterContext
import kjob.core.dsl.KJobFunctions import kjob.core.dsl.KJobFunctions
import kjob.core.kjob import kjob.core.kjob
import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import dev.usbharu.hideout.core.external.job.HideoutJob as HJ
import kjob.core.dsl.JobContextWithProps as JCWP
@Service @Service
@ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "false", matchIfMissing = true) @ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "false", matchIfMissing = true)
@ -23,9 +23,7 @@ class KJobJobQueueWorkerService() : JobQueueWorkerService {
}.start() }.start()
} }
override fun init( override fun <T, R : HideoutJob<T, R>> init(defines: List<Pair<R, JobRegisterContext<R, JobContextWithProps<R>>.(R) -> KJobFunctions<R, JobContextWithProps<R>>>>) {
defines: List<Pair<HJ, JobRegisterContext<HJ, JCWP<HJ>>.(HJ) -> KJobFunctions<HJ, JCWP<HJ>>>>
) {
defines.forEach { job -> defines.forEach { job ->
kjob.register(job.first, job.second) kjob.register(job.first, job.second)
} }

View File

@ -0,0 +1,8 @@
package dev.usbharu.hideout.core.service.job
import dev.usbharu.hideout.core.external.job.HideoutJob
interface JobProcessorService<T, R : HideoutJob<T, R>> {
suspend fun process(param: T)
suspend fun job(): Class<R>
}

View File

@ -8,7 +8,7 @@ import kjob.core.dsl.JobRegisterContext as JRC
@Service @Service
interface JobQueueWorkerService { interface JobQueueWorkerService {
fun init( fun <T, R : HJ<T, R>> init(
defines: List<Pair<HJ, JRC<HJ, JCWP<HJ>>.(HJ) -> KJobFunctions<HJ, JCWP<HJ>>>> defines: List<Pair<R, JRC<R, JCWP<R>>.(R) -> KJobFunctions<R, JCWP<R>>>>
) )
} }