jvmMain.assembly.RaptorJobsComponent.kt Maven / Gradle / Ivy
package io.fluidsonic.raptor
import io.fluidsonic.raptor.di.*
import kotlin.collections.set
import kotlin.reflect.*
public class RaptorJobsComponent internal constructor() : RaptorComponent.Base(RaptorJobsPlugin) {
private val executorsById: MutableMap> = hashMapOf()
internal fun complete(): RaptorJobRegistry =
RaptorJobRegistry(executorsById.values)
@RaptorDsl
public fun register(executor: RaptorJobExecutor) {
val id = executor.group.id
check(!executorsById.containsKey(id)) { "Cannot register multiple job executors with same ID: $id" }
executorsById[id] = executor
}
}
@RaptorDsl
public inline fun RaptorAssemblyQuery.register(
group: RaptorJobGroup,
noinline execute: suspend Dependency.(data: Data) -> Unit,
) {
register(group = group, dependencyType = typeOf(), execute = execute)
}
@RaptorDsl
public fun RaptorAssemblyQuery.register(
group: RaptorJobGroup,
dependencyType: KType,
execute: suspend Dependency.(data: Data) -> Unit,
) {
register(group.executor { data ->
val dependency = di.get(dependencyType) as Dependency
dependency.execute(data)
})
}
@RaptorDsl
public fun RaptorAssemblyQuery.register(executor: RaptorJobExecutor) {
this { register(executor) }
}