feat: Inboxのジョブキューを型安全ジョブキュー実装に切り替え

This commit is contained in:
usbharu 2023-11-26 15:36:43 +09:00
parent abce56e52d
commit 9171e3a063
2 changed files with 34 additions and 5 deletions

View File

@ -93,8 +93,36 @@ class InboxJobProcessor(
}
override suspend fun process(param: InboxJobParam) {
println(param)
System.err.println("aaaaaaaaaaaaaaaaaaaaaaaaaaa")
val jsonNode = objectMapper.readTree(param.json)
logger.info("START Process inbox. type: {}", param.type)
logger.trace("type: {}\njson: \n{}", param.type, jsonNode.toPrettyString())
val map = objectMapper.readValue<Map<String, List<String>>>(param.headers)
val httpRequest = objectMapper.readValue<HttpRequest>(param.httpRequest).copy(headers = HttpHeaders(map))
logger.trace("Request: {}\nheaders: {}", httpRequest, map)
val signature = parseSignatureHeader(httpRequest.headers)
logger.debug("Has signature? {}", signature != null)
val verify = signature?.let { verifyHttpSignature(httpRequest, it) } ?: false
logger.debug("Is verifying success? {}", verify)
val activityPubProcessor = activityPubProcessorList.firstOrNull { it.isSupported(param.type) }
if (activityPubProcessor == null) {
logger.warn("ActivityType {} is not support.", param.type)
throw IllegalStateException("ActivityPubProcessor not found.")
}
val value = objectMapper.treeToValue(jsonNode, activityPubProcessor.type())
activityPubProcessor.process(ActivityPubProcessContext(value, jsonNode, httpRequest, signature, verify))
logger.info("SUCCESS Process inbox. type: {}", param.type)
}
override fun job(): InboxJob = InboxJob

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.core.external.job
import dev.usbharu.hideout.activitypub.service.common.ActivityType
import kjob.core.Job
import kjob.core.Prop
import kjob.core.dsl.ScheduleContext
@ -129,7 +130,7 @@ object DeliverRemoveReactionJob :
data class InboxJobParam(
val json: String,
val type: String,
val type: ActivityType,
val httpRequest: String,
val headers: String
)
@ -143,14 +144,14 @@ object InboxJob : HideoutJob<InboxJobParam, InboxJob>("InboxJob") {
override fun convert(value: InboxJobParam): ScheduleContext<InboxJob>.(InboxJob) -> Unit = {
props[json] = value.json
props[type] = value.type
props[type] = value.type.name
props[httpRequest] = value.httpRequest
props[headers] = value.headers
}
override fun convert(props: JobProps<InboxJob>): InboxJobParam = InboxJobParam(
props[json],
props[type],
ActivityType.valueOf(props[type]),
props[httpRequest],
props[headers]
)