From dcac609b9432837fe38270301364d6e3e5345069 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 25 Nov 2023 16:46:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9E=8B=E5=AE=89=E5=85=A8=E3=82=B8?= =?UTF-8?q?=E3=83=A7=E3=83=96=E3=82=AD=E3=83=A5=E3=83=BC=E3=82=92=E3=81=99?= =?UTF-8?q?=E3=81=B9=E3=81=A6=E3=81=AE=E3=82=B8=E3=83=A7=E3=83=96=E3=82=AD?= =?UTF-8?q?=E3=83=A5=E3=83=BC=E3=81=AB=E9=81=A9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/core/external/job/HideoutJob.kt | 118 ++++++++++++++++-- .../core/service/job/JobQueueParentService.kt | 2 + 2 files changed, 107 insertions(+), 13 deletions(-) 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 9c4687d6..30c02371 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 @@ -11,54 +11,146 @@ abstract class HideoutJob>(name: String = "") : Job(name abstract fun convert(props: JobProps): T } +data class ReceiveFollowJobParam( + val actor: String, + val follow: String, + val targetActor: String +) + @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(value: ReceiveFollowJobParam): ScheduleContext.(ReceiveFollowJob) -> Unit = { + props[follow] = value.follow + props[actor] = value.actor + props[targetActor] = value.targetActor + } - override fun convert(props: JobProps): String = TODO("Not yet implemented") + override fun convert(props: JobProps): ReceiveFollowJobParam = ReceiveFollowJobParam( + actor = props[actor], + follow = props[follow], + targetActor = props[targetActor] + ) } +data class DeliverPostJobParam( + val create: String, + val inbox: String, + val actor: String +) + @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(value: DeliverPostJobParam): ScheduleContext.(DeliverPostJob) -> Unit = { + props[create] = value.create + props[inbox] = value.inbox + props[actor] = value.actor } - override fun convert(props: JobProps): String { - TODO("Not yet implemented") - } + override fun convert(props: JobProps): DeliverPostJobParam = DeliverPostJobParam( + create = props[create], + inbox = props[inbox], + actor = props[actor] + ) } +data class DeliverReactionJobParam( + val reaction: String, + val postUrl: String, + val actor: String, + val inbox: String, + val id: String +) + @Component -object DeliverReactionJob : HideoutJob("DeliverReactionJob") { +object DeliverReactionJob : HideoutJob("DeliverReactionJob") { val reaction: Prop = string("reaction") val postUrl: Prop = string("postUrl") val actor: Prop = string("actor") val inbox: Prop = string("inbox") val id: Prop = string("id") + override fun convert(value: DeliverReactionJobParam): ScheduleContext.(DeliverReactionJob) -> Unit = + { + props[reaction] = value.reaction + props[postUrl] = value.postUrl + props[actor] = value.actor + props[inbox] = value.inbox + props[id] = value.id + } + + override fun convert(props: JobProps): DeliverReactionJobParam = DeliverReactionJobParam( + props[reaction], + props[postUrl], + props[actor], + props[inbox], + props[id] + ) } +data class DeliverRemoveReactionJobParam( + val id: String, + val inbox: String, + val actor: String, + val like: String +) + @Component -object DeliverRemoveReactionJob : HideoutJob("DeliverRemoveReactionJob") { +object DeliverRemoveReactionJob : + HideoutJob("DeliverRemoveReactionJob") { val id: Prop = string("id") val inbox: Prop = string("inbox") val actor: Prop = string("actor") val like: Prop = string("like") + + override fun convert(value: DeliverRemoveReactionJobParam): ScheduleContext.(DeliverRemoveReactionJob) -> Unit = + { + props[id] = value.id + props[inbox] = value.inbox + props[actor] = value.actor + props[like] = value.like + } + + override fun convert(props: JobProps): DeliverRemoveReactionJobParam = + DeliverRemoveReactionJobParam( + id = props[id], + inbox = props[inbox], + actor = props[actor], + like = props[like] + ) } +data class InboxJobParam( + val json: String, + val type: String, + val httpRequest: String, + val headers: String +) + @Component -object InboxJob : HideoutJob("InboxJob") { +object InboxJob : HideoutJob("InboxJob") { val json = string("json") val type = string("type") val httpRequest = string("http_request") val headers = string("headers") + + override fun convert(value: InboxJobParam): ScheduleContext.(InboxJob) -> Unit = { + props[json] = value.json + props[type] = value.type + props[httpRequest] = value.httpRequest + props[headers] = value.headers + } + + override fun convert(props: JobProps): InboxJobParam = InboxJobParam( + props[json], + props[type], + props[httpRequest], + props[headers] + ) } 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 eee6d660..acec3f4a 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 @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service interface JobQueueParentService { fun init(jobDefines: List) + + @Deprecated("use type safe → scheduleTypeSafe") suspend fun schedule(job: J, block: ScheduleContext.(J) -> Unit = {}) suspend fun > scheduleTypeSafe(job: J, jobProps: T) }