Projection + aggregation change

This commit is contained in:
Brage Skjønborg 2026-01-30 14:39:37 +01:00
parent 8f06f8682d
commit 6a423365cd
4 changed files with 20 additions and 4 deletions

View File

@ -66,7 +66,7 @@ class MigrateCreateStoreTaskListener(
).derivedOf(event)
if (!collectProjection.canStoreAutomatically()) {
if (!collectProjection.isStorePermitted()) {
log.info { "Not storing content and metadata automatically for collection: $collection @ ${useEvent.referenceId}" }
log.info { "A manual allow completion event is required to proceed." }
return null

View File

@ -2,6 +2,7 @@ package no.iktdev.mediaprocessing.coordinator.services
import no.iktdev.eventi.ZDS.toEvent
import no.iktdev.eventi.models.store.PersistedEvent
import no.iktdev.mediaprocessing.shared.common.dto.CurrentState
import no.iktdev.mediaprocessing.shared.common.dto.Mode
import no.iktdev.mediaprocessing.shared.common.dto.SequenceSummary
import no.iktdev.mediaprocessing.shared.common.event_task_contract.events.CollectedEvent
@ -46,6 +47,10 @@ class SequenceAggregatorService() {
val projection = CollectProjection(domainEvents)
val state = if (events.any { it.event == CollectedEvent::class.java.simpleName }) {
if (projection.isStorePermitted()) CurrentState.Continuing else CurrentState.OnHold
} else CurrentState.Continuing
return SequenceSummary(
referenceId = last.referenceId.toString(),
title = "",
@ -62,6 +67,7 @@ class SequenceAggregatorService() {
StartFlow.Manual -> Mode.Manual
else -> Mode.Auto
},
currentState = state,
hasErrors = projection.getTaskStatus().any { it == CollectProjection.TaskStatus.Failed }
)
}

View File

@ -16,6 +16,7 @@ data class SequenceSummary(
val convertTaskStatus: CollectProjection.TaskStatus,
val coverDownloadTaskStatus: CollectProjection.TaskStatus,
val mode: Mode,
val currentState: CurrentState,
val hasErrors: Boolean,
)
@ -27,4 +28,9 @@ enum class ContextType {
enum class Mode {
Auto,
Manual
}
enum class CurrentState {
Continuing,
OnHold
}

View File

@ -41,9 +41,13 @@ class CollectProjection(val events: List<Event>) {
coverDownloadTaskStatus
)
fun canStoreAutomatically(): Boolean {
val manualEvent = events.filterIsInstance<StartProcessingEvent>().lastOrNull()
return manualEvent?.data?.flow != StartFlow.Manual
fun isStorePermitted(): Boolean {
val isAuto = events.filterIsInstance<StartProcessingEvent>().lastOrNull()?.data?.flow == StartFlow.Auto
if (isAuto) {
return true
}
val anyAllow = events.filterIsInstance<ManualAllowCompletionEvent>().lastOrNull()
return anyAllow != null
}
private fun projectUseFile(): File? {