Skip to content

Commit

Permalink
feat: 포즈 데이터 통계 처리 dev api
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 30, 2024
1 parent eb0fc23 commit 1b43098
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ class PoseCountUpdateJob(
* **전날 종합 데이터 업데이트**
* - 전날 데이터의 싱크가 틀린 경우가 발생했을 때를 대비하여, 새벽에 이전 데이터 정합도를 다시 한번 체크한다.
*/
suspend fun run() {
suspend fun run(targetDate: LocalDate) {
logger.info { "start PoseCountUpdateJob.run()" }

val targetDate = LocalDate.now().minusDays(1)

/** user의 수가 적으므로, 전체 uid를 조회, 만약에 oom이 터진다면, 서비스 대박임 */
val uids = userInfoService.findAllUids()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.time.LocalDate

@Component
class PoseCountScheduler(
private val poseCountUpdateJob: PoseCountUpdateJob
) {
private val logger = KotlinLogging.logger { }

/** 전일 데이터에 대한 정합성 체크 */
@Scheduled(cron = "0 0 4 * * *")
fun poseCountUpdateJob() {
val targetDate = LocalDate.now().minusDays(1)

CoroutineScope(Dispatchers.IO).launch {
runCatching {
withContext(Dispatchers.IO) {
retryOnError(2) {
poseCountUpdateJob.run()
poseCountUpdateJob.run(targetDate)
}
}
}.onFailure { e ->
logger.resolveCancellation("poseCountUpdateJob", e)
logger.resolveCancellation("poseCountUpdateJob targetDate: $targetDate", e)
}.getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hero.alignlab.domain.dev.resource

import com.hero.alignlab.batch.posecount.job.PoseCountUpdateJob
import com.hero.alignlab.common.extension.wrapVoid
import com.hero.alignlab.config.dev.DevResourceCheckConfig.Companion.devResource
import com.hero.alignlab.config.swagger.SwaggerTag.DEV_TAG
Expand All @@ -9,12 +10,14 @@ import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*
import java.time.LocalDate

@Tag(name = DEV_TAG)
@RestController
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
class DevPoseResource(
private val devPoseService: DevPoseService,
private val poseCountUpdateJob: PoseCountUpdateJob,
) {
@Operation(summary = "[DEV] 포즈 스냅샷 생성")
@PostMapping("/api/dev/v1/pose-snapshots")
Expand All @@ -32,4 +35,13 @@ class DevPoseResource(
) = devResource(token) {
devPoseService.deleteAllPoseData()
}

@Operation(summary = "[DEV] 포즈 데이터 통계 처리")
@PostMapping("/api/dev/v1/pose-counts")
suspend fun updatePoseCounts(
@RequestHeader("X-HERO-DEV-TOKEN") token: String,
@RequestParam targetDate: LocalDate
) = devResource(token) {
poseCountUpdateJob.run(targetDate)
}
}

0 comments on commit 1b43098

Please sign in to comment.