From d2c1e8ccb72390b2fbc1ff08a1bb8367c40c0e2a Mon Sep 17 00:00:00 2001 From: bskjon Date: Mon, 6 Jan 2025 03:38:30 +0100 Subject: [PATCH] Adding logging --- .../mapping/store/ContentCatalogStore.kt | 26 ++++++++++++++++--- .../mapping/store/ContentCompletionMover.kt | 12 ++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) 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 7c7499e0..cd8dd871 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 @@ -7,6 +7,7 @@ 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 @@ -47,14 +48,15 @@ object ContentCatalogStore { } fun storeCatalog(title: String, collection: String, type: String, cover: String?, genres: String?): Int? { - withTransaction(getStoreDatabase().database, block = { + val status = executeWithStatus(getStoreDatabase().database, block = { val existingRow = catalog.select { (catalog.collection eq collection) and (catalog.type eq type) }.firstOrNull() if (existingRow == null) { - catalog.insertIgnore { + log.info { "$collection does not exist, and will be created" } + catalog.insert { it[catalog.title] = title it[catalog.cover] = cover it[catalog.type] = type @@ -78,6 +80,11 @@ object ContentCatalogStore { }, { log.error { "Failed to store catalog $collection: ${it.message}" } }) + if (status) { + log.info { "$collection was successfully stored!" } + } else { + log.error { "Unable to store catalog $collection..." } + } return getId(title, collection, type) } @@ -86,7 +93,7 @@ object ContentCatalogStore { log.error { "Movie id was not returned!" } return } - withTransaction(getStoreDatabase().database, block = { + val status = executeWithStatus(getStoreDatabase().database, block = { catalog.update({ (catalog.id eq catalogId) }) { @@ -95,6 +102,11 @@ object ContentCatalogStore { }, { log.error { "Failed to store movie ${videoDetails.fileName}: ${it.message}" } }) + if (status) { + log.info { "${videoDetails.fileName} was successfully stored in movies!" } + } else { + log.error { "Unable to store catalog ${videoDetails.fileName} in movies..." } + } } private fun storeSerie(collection: String, videoDetails: VideoDetails) { @@ -126,7 +138,11 @@ object ContentCatalogStore { }, { log.error { "Failed to store serie: ${it.message}" } }) if (!finalStatus) { log.error { "Failed to insert ${videoDetails.fileName} with fallback season 0" } + } else { + log.info { "${videoDetails.fileName} was successfully stored in movies with fallback season 0!" } } + } else { + log.info { "${videoDetails.fileName} was successfully stored in series!" } } } @@ -135,6 +151,10 @@ object ContentCatalogStore { when (type) { "movie" -> storeMovie(catalogId, videoDetails) "serie" -> storeSerie(collection, videoDetails) + else -> { + log.error { "$type was provided for the function storeMedia, thus failing" } + throw RuntimeException("Illegal type provided") + } } } diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt index 34cc6e57..8b81850b 100644 --- a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt @@ -36,9 +36,11 @@ class ContentCompletionMover(val collection: String, val events: List) { } val storeFile = storeFolder.using(encodedFile.name) val result = encodedFile.moveTo(storeFile) { - } - return if (result) Pair(encodedFile.absolutePath, storeFile.absolutePath) else throw RuntimeException("Unable to movie file ${encodedFile.absolutePath} to ${storeFile.absolutePath}") + return if (result) run { + log.info { "Moved ${encodedFile.absolutePath} to ${storeFile.absolutePath} for permanent storage and usage" } + Pair(encodedFile.absolutePath, storeFile.absolutePath) + } else throw RuntimeException("Unable to movie file ${encodedFile.absolutePath} to ${storeFile.absolutePath}") } fun moveCover(): Pair? { @@ -56,7 +58,10 @@ class ContentCompletionMover(val collection: String, val events: List) { return Pair(coverFile.absolutePath, storeFile.absolutePath) } val result = coverFile.moveTo(storeFile) - return if (result) Pair(coverFile.absolutePath, storeFile.absolutePath) else null + return if (result) { + log.info { "Moved ${coverFile.absolutePath} to ${storeFile.absolutePath} for permanent storage and usage" } + Pair(coverFile.absolutePath, storeFile.absolutePath) + } else null } @@ -115,6 +120,7 @@ class ContentCompletionMover(val collection: String, val events: List) { val storeFile = languageFolder.using("${movable.storeFileName}.${movable.cachedFile.extension}") val success = movable.cachedFile.moveTo(storeFile) if (success) { + log.info { "Moved ${movable.cachedFile.absolutePath} to ${storeFile.absolutePath} for permanent storage and usage" } moved.add(MovedSubtitle(movable.language, movable.cachedFile.absolutePath, storeFile.absolutePath)) } }