Skip to content

Commit

Permalink
얼굴 실섭에서만 블러처리하기 & 크론잡 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yongseongkim committed Sep 8, 2024
1 parent 8f69c8b commit 5506f4b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ open class AccessibilityImageFaceBlurringService(
detectedPeopleCount = 0
)
val (blurredImageUrl, detectedPositions) = run {
logger.info { "Detected ${detected.positions.size} faces in the image($imageUrl) from bytes(${detected.imageBytes.size}) | width = ${detected.imageSize.width}, height = ${detected.imageSize.height}" }
val outputByteArray = imageProcessor.blur(imageBytes, extension, detected.positions)
val blurredImageUrl = fileManagementService.uploadImage("${name}_b.$extension", outputByteArray)
blurredImageUrl to detected.positions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import club.staircrusher.accessibility.domain.model.PlaceAccessibility
import club.staircrusher.stdlib.clock.SccClock
import club.staircrusher.stdlib.di.annotation.Component
import club.staircrusher.stdlib.domain.entity.EntityIdGenerator
import club.staircrusher.stdlib.env.SccEnv
import club.staircrusher.stdlib.persistence.TransactionManager
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
Expand All @@ -26,6 +27,10 @@ class BlurFacesInLatestPlaceAccessibilityImagesUseCase(
private val taskExecutor = Executors.newCachedThreadPool()

fun handleAsync() {
if (SccEnv.isProduction().not()) {
logger.info { "Skip blurring faces in the latest place accessibility images because it's not a production environment." }
return
}
taskExecutor.execute {
handle()
}
Expand All @@ -45,12 +50,6 @@ class BlurFacesInLatestPlaceAccessibilityImagesUseCase(
val result =
runBlocking { accessibilityImageFaceBlurringService.blurFacesInPlaceAccessibility(targetAccessibility.id) }
?: return
logger.info {
"Blurred faces in the latest place accessibility images. ${
result.entranceResults.joinToString(",") { "${it.originalImageUrl} -> ${it.blurredImageUrl}" }
}"
}

val entranceResults = result.entranceResults
transactionManager.doInTransaction {
val imageUrls = entranceResults.map { it.blurredImageUrl }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ enum class SccEnv {
fun getEnv(): SccEnv {
return checkNotNull(value) { "SccEnv has not been set." }
}

fun isProduction(): Boolean {
return getEnv() == SccEnv.PROD
}
}
}
25 changes: 24 additions & 1 deletion infra/helm/scc-server/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: scc-update-ranking
labels:
{{- include "scc-server.labels" . | nindent 4 }}
spec:
# Run every minute from 12:00AM to 08:00AM
schedule: "* 0-8 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: curl-container
image: appropriate/curl
args:
- "--fail"
- "-XPOST"
- "http://scc-server.{{ .Release.Namespace }}.svc.cluster.local/blurFacesInLatestPlaceAccessibilityImages"
restartPolicy: OnFailure
---

apiVersion: batch/v1
kind: CronJob
metadata:
Expand All @@ -13,7 +36,7 @@ spec:
containers:
- name: curl-container
image: appropriate/curl
args:
args:
- "--fail"
- "-XPOST"
- "http://scc-server.{{ .Release.Namespace }}.svc.cluster.local/updateAccessibilityRanks"
Expand Down

0 comments on commit 5506f4b

Please sign in to comment.