mirror of https://github.com/usbharu/Hideout.git
feat: EmbeddedOwlProducerを追加
This commit is contained in:
parent
297c29f020
commit
949b0a935f
|
@ -18,7 +18,7 @@ package dev.usbharu.owl.producer.embedded
|
||||||
|
|
||||||
import dev.usbharu.owl.broker.ModuleContext
|
import dev.usbharu.owl.broker.ModuleContext
|
||||||
import dev.usbharu.owl.broker.OwlBrokerApplication
|
import dev.usbharu.owl.broker.OwlBrokerApplication
|
||||||
import dev.usbharu.owl.broker.service.*
|
import dev.usbharu.owl.broker.service.RetryPolicyFactory
|
||||||
import dev.usbharu.owl.common.task.PublishedTask
|
import dev.usbharu.owl.common.task.PublishedTask
|
||||||
import dev.usbharu.owl.common.task.Task
|
import dev.usbharu.owl.common.task.Task
|
||||||
import dev.usbharu.owl.common.task.TaskDefinition
|
import dev.usbharu.owl.common.task.TaskDefinition
|
||||||
|
@ -27,22 +27,16 @@ import org.koin.core.Koin
|
||||||
import org.koin.core.context.GlobalContext.startKoin
|
import org.koin.core.context.GlobalContext.startKoin
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koin.ksp.generated.defaultModule
|
import org.koin.ksp.generated.defaultModule
|
||||||
import java.time.Instant
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class EmbeddedGrpcOwlProducer(
|
class EmbeddedGrpcOwlProducer(
|
||||||
private val moduleContext: ModuleContext,
|
private val moduleContext: ModuleContext,
|
||||||
private val retryPolicyFactory: RetryPolicyFactory,
|
private val retryPolicyFactory: RetryPolicyFactory,
|
||||||
private val name: String,
|
|
||||||
private val port: Int,
|
private val port: Int,
|
||||||
private val owlProducer: OwlProducer,
|
private val owlProducer: OwlProducer,
|
||||||
) : OwlProducer {
|
) : OwlProducer {
|
||||||
private lateinit var producerId: UUID
|
|
||||||
|
|
||||||
private lateinit var application: Koin
|
private lateinit var application: Koin
|
||||||
|
|
||||||
private val taskMap: MutableMap<Class<*>, TaskDefinition<*>> = mutableMapOf()
|
|
||||||
|
|
||||||
override suspend fun start() {
|
override suspend fun start() {
|
||||||
application = startKoin {
|
application = startKoin {
|
||||||
printLogger()
|
printLogger()
|
||||||
|
@ -55,45 +49,14 @@ class EmbeddedGrpcOwlProducer(
|
||||||
modules(module, defaultModule, moduleContext.module())
|
modules(module, defaultModule, moduleContext.module())
|
||||||
}.koin
|
}.koin
|
||||||
|
|
||||||
val producerService = application.get<ProducerService>()
|
|
||||||
|
|
||||||
producerId = producerService.registerProducer(RegisterProducerRequest(name, name))
|
|
||||||
|
|
||||||
application.get<OwlBrokerApplication>().start(port)
|
application.get<OwlBrokerApplication>().start(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun <T : Task> registerTask(taskDefinition: TaskDefinition<T>) {
|
override suspend fun <T : Task> registerTask(taskDefinition: TaskDefinition<T>) {
|
||||||
application.get<RegisterTaskService>()
|
owlProducer.registerTask(taskDefinition)
|
||||||
.registerTask(
|
|
||||||
dev.usbharu.owl.broker.domain.model.taskdefinition.TaskDefinition(
|
|
||||||
name = taskDefinition.name,
|
|
||||||
priority = taskDefinition.priority,
|
|
||||||
maxRetry = taskDefinition.maxRetry,
|
|
||||||
timeoutMilli = taskDefinition.timeoutMilli,
|
|
||||||
propertyDefinitionHash = taskDefinition.propertyDefinition.hash(),
|
|
||||||
retryPolicy = taskDefinition.retryPolicy
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
taskMap[taskDefinition.type] = taskDefinition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun <T : Task> publishTask(task: T): PublishedTask<T> {
|
override suspend fun <T : Task> publishTask(task: T): PublishedTask<T> {
|
||||||
|
return owlProducer.publishTask(task)
|
||||||
val taskDefinition = taskMap.getValue(task::class.java) as TaskDefinition<T>
|
|
||||||
|
|
||||||
val publishTask = application.get<TaskPublishService>().publishTask(
|
|
||||||
PublishTask(
|
|
||||||
taskDefinition.name,
|
|
||||||
producerId,
|
|
||||||
taskDefinition.serialize(task)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return PublishedTask(
|
|
||||||
task,
|
|
||||||
publishTask.id,
|
|
||||||
Instant.now()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue