Skip to content

Commit

Permalink
feat: add logs for thumbnail generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoo0515 committed Jul 6, 2024
1 parent 5c787b4 commit ab27833
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class AccessibilityApplicationService(
try {
accessibilityImageService.migrateImageUrlsToImagesIfNeeded(placeId)
accessibilityImageService.generateThumbnailsIfNeeded(placeId)
logger.info { "Thumbnail generation complete" }
} catch (e: Throwable) {
logger.error(e) { "Failed to generate thumbnail and migrate images for place $placeId" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AccessibilityImageService(
.let { uploadThumbnailImages(it) }

if (generatedThumbnailUrls.isNotEmpty()) {
logger.info { "Saving generated thumbnail urls to DB" }
saveThumbnailUrls(placeId, generatedThumbnailUrls)
}
}
Expand Down Expand Up @@ -105,11 +106,13 @@ class AccessibilityImageService(

private fun generateThumbnail(originalImageUrl: String, placeId: String): Thumbnail? {
try {
logger.info { "Generating thumbnail for place: $placeId, image: $originalImageUrl" }
val destinationPath = thumbnailPath.resolve(placeId).createDirectory()
val imageFile = fileManagementService.downloadFile(originalImageUrl, destinationPath)
val thumbnailFileName = "thumbnail_${imageFile.nameWithoutExtension}.$THUMBNAIL_FORMAT"
val thumbnailOutputStream = thumbnailGenerator.generate(imageFile, THUMBNAIL_FORMAT)

logger.info { "Thumbnail thumbnail for place: $placeId, image: $originalImageUrl"}
return Thumbnail(originalImageUrl, thumbnailFileName, thumbnailOutputStream)
} catch (t: Throwable) {
logger.error(t) { "Failed to generate thumbnail for place: $placeId, image: $originalImageUrl" }
Expand All @@ -119,6 +122,7 @@ class AccessibilityImageService(

// FIXME: ThumbnailUploadResult 같은 data class를 만들어서 반환하면 findGeneratedThumbnailUrl에서 온몸비틀기를 안 해도 될지도?
private fun uploadThumbnailImages(thumbnails: List<Thumbnail>) = runBlocking {
logger.info { "Uploading thumbnails" }
return@runBlocking thumbnails
.map { (_, fileName, outputStream) ->
async { fileManagementService.uploadThumbnailImage(fileName, outputStream) }
Expand Down

0 comments on commit ab27833

Please sign in to comment.