setting parent

This commit is contained in:
bskjon committed 2026-06-30 23:27:59 +02:00
1 parent f5a08268aa
commit ba5231aaf6
2 files changed
+10

No files matched your search

@@ -51,6 +51,10 @@ open class EventDispatcher(val eventStore: EventStore, private val lifecycleStor
//log.debug("Evaluating candidate: ${candidate::class.simpleName} for listener ${listener::class.simpleName}")
try {
val result = listener.onEvent(candidate, effectiveHistory)
if (result?.hasReferenceIdBeenSet() == false) {
log.warn { "ReferenceId is missing on produced event when dispatched ${candidate::class.simpleName}, setting this as parent for produced event!" }
result.apply { derivedOf(candidate) }
}
if (result != null) {
validateReferenceId(result, listener)
@@ -7,6 +7,7 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import mu.KotlinLogging
import no.iktdev.eventi.models.Event
import no.iktdev.eventi.models.Progress
import no.iktdev.eventi.models.Task
@@ -23,6 +24,7 @@ import kotlin.coroutines.cancellation.CancellationException
* @param reporter An instance of [TaskReporter] for reporting task status and events.
*/
abstract class TaskListener(val taskType: TaskType = TaskType.CPU_INTENSIVE): TaskListenerImplementation {
private val log = KotlinLogging.logger {}
init {
TaskListenerRegistry.registerListener(this)
@@ -75,6 +77,10 @@ abstract class TaskListener(val taskType: TaskType = TaskType.CPU_INTENSIVE): Ta
currentJob = getDispatcherForTask(task).launch {
try {
val result = onTask(task)
if (result?.hasReferenceIdBeenSet() == false) {
log.warn { "ReferenceId is missing on produced result event from task ${task.taskId} (${task.javaClass.simpleName}, derivation and reference id will be inherited from the task" }
result.apply { producedFrom(task) }
}
if (result != null) {
validateReferenceId(result, this@TaskListener)
}