From db333920a104acd35ddfb7a7a00cf9d4061a5627 Mon Sep 17 00:00:00 2001 From: bskjon Date: Mon, 24 Feb 2025 02:00:10 +0100 Subject: [PATCH] Logging + adjustments --- .../listeners/CompletedTaskListener.kt | 11 +++--- .../mapping/store/ContentCatalogStore.kt | 35 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt index ffa320ec..eff430e2 100644 --- a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt @@ -82,8 +82,7 @@ class CompletedTaskListener : CoordinatorEventListener() { } fun getVideo(events: List): VideoDetails? { - val mediaInfo = events.find { it.eventType == Events.ReadOutNameAndType } - ?.az() + val mediaInfo = events.find { it.eventType == Events.ReadOutNameAndType }?.az() val encoded = events.find { it.eventType == Events.WorkEncodePerformed }?.dataAs()?.outputFile if (encoded == null) { log.warn { "No encode no video details!" } @@ -95,7 +94,7 @@ class CompletedTaskListener : CoordinatorEventListener() { return null } - val details = VideoDetails( + return VideoDetails( type = proper.type, fileName = File(encoded).name, serieInfo = if (proper !is EpisodeInfo) null else SerieInfo( @@ -105,7 +104,6 @@ class CompletedTaskListener : CoordinatorEventListener() { title = proper.title ) ) - return details } override fun shouldIProcessAndHandleEvent(incomingEvent: Event, events: List): Boolean { @@ -172,13 +170,14 @@ class CompletedTaskListener : CoordinatorEventListener() { val videoInfo = getVideo(events) if (videoInfo != null) { - assert(persistedContent.video == null) ContentCatalogStore.storeMedia( title = completedData.metadataStored.title, collection = completedData.metadataStored.collection, type = completedData.metadataStored.type, videoDetails = videoInfo ) + } else { + log.info { "VideoInfo is null" } } @@ -269,7 +268,7 @@ class CompletedTaskListener : CoordinatorEventListener() { .setPrettyPrinting() .create() - log.info { "Events in complete:\n${gson.toJson(events)}" } + //log.info { "Events in complete:\n${gson.toJson(events)}" } val metadataFound = events.find { it.eventType == Events.MetadataSearchPerformed } if (metadataFound == null) { diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt index e750b83f..c5bb0899 100644 --- a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt @@ -1,23 +1,15 @@ package no.iktdev.mediaprocessing.coordinator.tasksV2.mapping.store import mu.KotlinLogging -import no.iktdev.eventi.database.executeOrException import no.iktdev.eventi.database.withTransaction import no.iktdev.mediaprocessing.coordinator.getStoreDatabase -import no.iktdev.mediaprocessing.shared.common.contract.reader.MetadataDto import no.iktdev.mediaprocessing.shared.common.contract.reader.VideoDetails -import no.iktdev.mediaprocessing.shared.common.parsing.NameHelper import no.iktdev.streamit.library.db.executeWithStatus import no.iktdev.streamit.library.db.insertWithSuccess -import no.iktdev.streamit.library.db.query.CatalogQuery import no.iktdev.streamit.library.db.query.MovieQuery -import no.iktdev.streamit.library.db.query.SerieQuery import no.iktdev.streamit.library.db.tables.catalog import no.iktdev.streamit.library.db.tables.serie -import no.iktdev.streamit.library.db.withTransaction -import org.jetbrains.exposed.exceptions.ExposedSQLException import org.jetbrains.exposed.sql.* -import java.sql.SQLIntegrityConstraintViolationException object ContentCatalogStore { val log = KotlinLogging.logger {} @@ -85,7 +77,7 @@ object ContentCatalogStore { } else { log.error { "Unable to store catalog $collection..." } } - return getId(title, collection, type) + return getId(title, type) } private fun storeMovie(catalogId: Int, videoDetails: VideoDetails) { @@ -148,7 +140,10 @@ object ContentCatalogStore { } fun storeMedia(title: String, collection: String, type: String, videoDetails: VideoDetails) { - val catalogId = getId(title, collection, type) ?: return + val catalogId = getId(title, type) ?: run { + log.warn { "Could not find id for $title with type $type" } + return + } log.info { "$title is identified as $type" } when (type) { "movie" -> storeMovie(catalogId, videoDetails) @@ -160,12 +155,20 @@ object ContentCatalogStore { } } - fun getId(title: String, collection: String, type: String): Int? { - return withTransaction(getStoreDatabase().database, block = { - catalog.select { catalog.title eq title }.andWhere { - catalog.type eq type - }.map { it[catalog.id].value }.firstOrNull() - }) + private fun getId(title: String, type: String): Int? { + val ids = withTransaction(getStoreDatabase().database) { + catalog.select { + (catalog.title eq title) + .and(catalog.type eq type) + }.map { it[catalog.id].value } + } ?: run { + log.warn { "No values found on $title with type $type" } + return null + } + if (ids.size > 1) { + log.info { "Found ids: ${ids.joinToString(",")}" } + } + return ids.firstOrNull() }