This commit is contained in:
bskjon 2025-02-23 21:09:30 +01:00
parent 5a50c986f4
commit 6e25d1e67f

View File

@ -2,6 +2,7 @@ package no.iktdev.mediaprocessing.coordinator.tasksV2.implementations
import com.google.gson.Gson import com.google.gson.Gson
import mu.KotlinLogging import mu.KotlinLogging
import no.iktdev.eventi.core.WGson
import no.iktdev.eventi.data.referenceId import no.iktdev.eventi.data.referenceId
import no.iktdev.mediaprocessing.coordinator.CoordinatorEventListener import no.iktdev.mediaprocessing.coordinator.CoordinatorEventListener
import no.iktdev.mediaprocessing.shared.common.contract.Events import no.iktdev.mediaprocessing.shared.common.contract.Events
@ -18,15 +19,29 @@ abstract class WorkTaskListener: CoordinatorEventListener() {
} }
fun canStart(incomingEvent: Event, events: List<Event>): Boolean { fun canStart(incomingEvent: Event, events: List<Event>): Boolean {
assert(events.isNotEmpty()) {
"Events are nor present"
}
val startEvent = events.find { it.eventType == Events.ProcessStarted }?.az<MediaProcessStartEvent>() val startEvent = events.find { it.eventType == Events.ProcessStarted }?.az<MediaProcessStartEvent>()
val startType = startEvent?.data?.type if (startEvent == null) {
if (startType == null) { log.error { "Start event not found on ${incomingEvent.referenceId()}." }
log.error { "Start event not found on ${incomingEvent.referenceId()}. Requiring permit event" }
try { try {
log.error { Gson().toJson(startEvent) } log.error { WGson.toJson(startEvent) }
log.warn { "Events provided:\n ${WGson.toJson(events)}" }
} catch (e: Exception) {} } catch (e: Exception) {}
return false return false
} }
val startType = startEvent?.data?.type
if (startEvent == null) {
log.error { "Start type on ${incomingEvent.referenceId()}. Requiring permit event" }
try {
log.error { WGson.toJson(startEvent) }
} catch (e: Exception) {}
return false
}
return if (incomingEvent.eventType == Events.WorkProceedPermitted) { return if (incomingEvent.eventType == Events.WorkProceedPermitted) {
return true return true
} else { } else {