mirror of https://github.com/usbharu/Hideout.git
feat: 起動時にタスク定義を読み込むように
This commit is contained in:
parent
7324e0b0e1
commit
f1f6166a78
|
@ -191,6 +191,7 @@ dependencies {
|
|||
implementation(libs.bundles.apache.tika)
|
||||
implementation(libs.bundles.openapi)
|
||||
implementation(libs.bundles.owl.producer)
|
||||
implementation(libs.bundles.owl.broker)
|
||||
implementation(libs.bundles.spring.boot.oauth2)
|
||||
implementation(libs.bundles.spring.boot.data.mongodb)
|
||||
implementation(libs.bundles.spring.boot.data.mongodb)
|
||||
|
|
|
@ -16,20 +16,23 @@
|
|||
|
||||
package dev.usbharu.hideout.application.config
|
||||
|
||||
import dev.usbharu.owl.broker.ModuleContext
|
||||
import dev.usbharu.owl.common.retry.RetryPolicyFactory
|
||||
import dev.usbharu.owl.producer.api.OWL
|
||||
import dev.usbharu.owl.producer.api.OwlProducer
|
||||
import dev.usbharu.owl.producer.defaultimpl.DEFAULT
|
||||
import dev.usbharu.owl.producer.embedded.EMBEDDED
|
||||
import dev.usbharu.owl.producer.embedded.EMBEDDED_GRPC
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import java.util.*
|
||||
|
||||
@Configuration
|
||||
class OwlConfig(private val producerConfig: ProducerConfig) {
|
||||
@Bean
|
||||
fun producer(retryPolicyFactory: RetryPolicyFactory? = null): OwlProducer {
|
||||
fun producer(@Autowired(required = false) retryPolicyFactory: RetryPolicyFactory? = null): OwlProducer {
|
||||
return when (producerConfig.mode) {
|
||||
ProducerMode.EMBEDDED -> {
|
||||
OWL(EMBEDDED) {
|
||||
|
@ -39,6 +42,10 @@ class OwlConfig(private val producerConfig: ProducerConfig) {
|
|||
if (producerConfig.port != null) {
|
||||
this.port = producerConfig.port.toString()
|
||||
}
|
||||
val moduleContext = ServiceLoader.load(ModuleContext::class.java).firstOrNull()
|
||||
if (moduleContext != null) {
|
||||
this.moduleContext = moduleContext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
35
hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt
vendored
Normal file
35
hideout-core/src/main/kotlin/dev/usbharu/hideout/application/external/OwlProducerRunner.kt
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2024 usbharu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dev.usbharu.hideout.application.external
|
||||
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import dev.usbharu.owl.producer.api.OwlProducer
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.springframework.boot.ApplicationArguments
|
||||
import org.springframework.boot.ApplicationRunner
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class OwlProducerRunner(private val owlProducer: OwlProducer, private val taskDefinitions: List<TaskDefinition<*>>) :
|
||||
ApplicationRunner {
|
||||
override fun run(args: ApplicationArguments?) {
|
||||
runBlocking {
|
||||
owlProducer.start()
|
||||
taskDefinitions.forEach { taskDefinition -> owlProducer.registerTask(taskDefinition) }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class DeliverAcceptTask(
|
||||
val accept: Accept,
|
||||
|
@ -28,6 +29,7 @@ data class DeliverAcceptTask(
|
|||
val signer: Long,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object DeliverAcceptTaskDef : TaskDefinition<DeliverAcceptTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class DeliverCreateTask(
|
||||
val create: Create,
|
||||
|
@ -28,6 +29,7 @@ data class DeliverCreateTask(
|
|||
val actor: String,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object DeliverCreateTaskDef : TaskDefinition<DeliverCreateTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class DeliverDeleteTask(
|
||||
val delete: Delete,
|
||||
|
@ -28,6 +29,7 @@ data class DeliverDeleteTask(
|
|||
val signer: Long,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object DeliverDeleteTaskDef : TaskDefinition<DeliverDeleteTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class DeliverReactionTask(
|
||||
val actor: String,
|
||||
|
@ -28,6 +29,7 @@ data class DeliverReactionTask(
|
|||
val inbox: String,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object DeliverReactionTaskDef : TaskDefinition<DeliverReactionTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class DeliverRejectTask(
|
||||
val reject: Reject,
|
||||
|
@ -28,6 +29,7 @@ data class DeliverRejectTask(
|
|||
val signer: Long,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object DeliverRejectTaskDef : TaskDefinition<DeliverRejectTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class DeliverUndoTask(
|
||||
val undo: Undo,
|
||||
|
@ -28,6 +29,7 @@ data class DeliverUndoTask(
|
|||
val signer: Long,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object DeliverUndoTaskDef : TaskDefinition<DeliverUndoTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -22,6 +22,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class InboxTask(
|
||||
val json: String,
|
||||
|
@ -30,6 +31,7 @@ data class InboxTask(
|
|||
val headers: Map<String, List<String>>,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object InboxTaskDef : TaskDefinition<InboxTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -21,6 +21,7 @@ import dev.usbharu.owl.common.property.PropertyValue
|
|||
import dev.usbharu.owl.common.task.PropertyDefinition
|
||||
import dev.usbharu.owl.common.task.Task
|
||||
import dev.usbharu.owl.common.task.TaskDefinition
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class ReceiveFollowTask(
|
||||
val actor: String,
|
||||
|
@ -28,6 +29,7 @@ data class ReceiveFollowTask(
|
|||
val targetActor: String,
|
||||
) : Task()
|
||||
|
||||
@Component
|
||||
data object ReceiveFollowTaskDef : TaskDefinition<ReceiveFollowTask> {
|
||||
override val name: String
|
||||
get() = TODO("Not yet implemented")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
hideout:
|
||||
url: "https://test-hideout.usbharu.dev"
|
||||
url: "https://test-hideout-dev.usbharu.dev"
|
||||
use-mongodb: true
|
||||
owl:
|
||||
producer:
|
||||
|
|
|
@ -60,6 +60,8 @@ kjon-mongo = { module = "org.drewcarlson:kjob-mongo", version.ref = "kjob" }
|
|||
owl-producer-api = { module = "dev.usbharu:owl-producer-api", version.ref = "owl" }
|
||||
owl-producer-default = { module = "dev.usbharu:owl-producer-default", version.ref = "owl" }
|
||||
owl-producer-embedded = { module = "dev.usbharu:owl-producer-embedded", version.ref = "owl" }
|
||||
owl-broker = { module = "dev.usbharu:owl-broker", version.ref = "owl" }
|
||||
owl-broker-mongodb = { module = "dev.usbharu:owl-broker-mongodb", version.ref = "owl" }
|
||||
|
||||
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
|
||||
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
|
||||
|
@ -76,6 +78,7 @@ serialization = ["serialization-core", "serialization-json"]
|
|||
apache-tika = ["apache-tika-core", "apache-tika-parsers"]
|
||||
kjob = ["kjon-core", "kjon-mongo"]
|
||||
owl-producer = ["owl-producer-api", "owl-producer-default", "owl-producer-embedded"]
|
||||
owl-broker = ["owl-broker", "owl-broker-mongodb"]
|
||||
|
||||
[plugins]
|
||||
|
||||
|
|
Loading…
Reference in New Issue