diff --git a/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt b/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt index 238b809f..9c4687d6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt @@ -2,26 +2,44 @@ package dev.usbharu.hideout.core.external.job import kjob.core.Job import kjob.core.Prop +import kjob.core.dsl.ScheduleContext +import kjob.core.job.JobProps import org.springframework.stereotype.Component -sealed class HideoutJob(name: String = "") : Job(name) +abstract class HideoutJob>(name: String = "") : Job(name) { + abstract fun convert(value: T): ScheduleContext.(R) -> Unit + abstract fun convert(props: JobProps): T +} @Component -object ReceiveFollowJob : HideoutJob("ReceiveFollowJob") { +object ReceiveFollowJob : HideoutJob("ReceiveFollowJob") { val actor: Prop = string("actor") val follow: Prop = string("follow") val targetActor: Prop = string("targetActor") + + override fun convert(value: String): ScheduleContext.(ReceiveFollowJob) -> Unit = { + props[it.follow] = value + } + + override fun convert(props: JobProps): String = TODO("Not yet implemented") } @Component -object DeliverPostJob : HideoutJob("DeliverPostJob") { +object DeliverPostJob : HideoutJob("DeliverPostJob") { val create = string("create") val inbox = string("inbox") val actor = string("actor") + override fun convert(value: String): ScheduleContext.(DeliverPostJob) -> Unit { + TODO("Not yet implemented") + } + + override fun convert(props: JobProps): String { + TODO("Not yet implemented") + } } @Component -object DeliverReactionJob : HideoutJob("DeliverReactionJob") { +object DeliverReactionJob : HideoutJob("DeliverReactionJob") { val reaction: Prop = string("reaction") val postUrl: Prop = string("postUrl") val actor: Prop = string("actor") @@ -30,7 +48,7 @@ object DeliverReactionJob : HideoutJob("DeliverReactionJob") { } @Component -object DeliverRemoveReactionJob : HideoutJob("DeliverRemoveReactionJob") { +object DeliverRemoveReactionJob : HideoutJob("DeliverRemoveReactionJob") { val id: Prop = string("id") val inbox: Prop = string("inbox") val actor: Prop = string("actor") @@ -38,7 +56,7 @@ object DeliverRemoveReactionJob : HideoutJob("DeliverRemoveReactionJob") { } @Component -object InboxJob : HideoutJob("InboxJob") { +object InboxJob : HideoutJob("InboxJob") { val json = string("json") val type = string("type") val httpRequest = string("http_request") diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueParentService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueParentService.kt index 0e02b011..5bc3ec89 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueParentService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueParentService.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.infrastructure.kjobexposed +import dev.usbharu.hideout.core.external.job.HideoutJob import dev.usbharu.hideout.core.service.job.JobQueueParentService import kjob.core.Job import kjob.core.KJob @@ -29,4 +30,9 @@ class KJobJobQueueParentService() : JobQueueParentService { logger.debug("schedule job={}", job.name) kjob.schedule(job, block) } + + override suspend fun > scheduleTypeSafe(job: J, jobProps: T) { + val convert: ScheduleContext.(J) -> Unit = job.convert(jobProps) + kjob.schedule(job, convert) + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/job/JobQueueParentService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/job/JobQueueParentService.kt index 38f8111f..eee6d660 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/job/JobQueueParentService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/job/JobQueueParentService.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.service.job +import dev.usbharu.hideout.core.external.job.HideoutJob import kjob.core.Job import kjob.core.dsl.ScheduleContext import org.springframework.stereotype.Service @@ -9,4 +10,5 @@ interface JobQueueParentService { fun init(jobDefines: List) suspend fun schedule(job: J, block: ScheduleContext.(J) -> Unit = {}) + suspend fun > scheduleTypeSafe(job: J, jobProps: T) }