feat(ranking): 스냅샷 job 실행 서비스를 추가한다

This commit is contained in:
2026-06-09 11:21:44 +09:00
parent 81d5f05adf
commit aad1f02648
3 changed files with 166 additions and 5 deletions

View File

@@ -0,0 +1,45 @@
package kr.co.vividnext.sodalive.v2.ranking.application
import kr.co.vividnext.sodalive.v2.ranking.domain.CreatorRankingPeriodPolicy
import kr.co.vividnext.sodalive.v2.ranking.port.out.CreatorRankingSnapshotJobPort
import kr.co.vividnext.sodalive.v2.ranking.port.out.CreatorRankingSnapshotJobRecord
import kr.co.vividnext.sodalive.v2.ranking.port.out.CreatorRankingSnapshotJobStatus
import kr.co.vividnext.sodalive.v2.ranking.port.out.CreatorRankingSnapshotJobTrigger
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import java.time.ZonedDateTime
@Service
class CreatorRankingSnapshotJobService(
private val refreshService: CreatorRankingSnapshotRefreshService,
private val jobPort: CreatorRankingSnapshotJobPort,
private val nowProvider: () -> ZonedDateTime = { ZonedDateTime.now() }
) {
private val periodPolicy = CreatorRankingPeriodPolicy()
fun refreshLastCompletedWeekByScheduledJob() {
val now = nowProvider()
val period = periodPolicy.resolveLastCompletedWeek(now)
val utcRange = periodPolicy.toUtcRange(period)
val job = jobPort.save(
CreatorRankingSnapshotJobRecord(
aggregationStartAtUtc = utcRange.startInclusiveUtc,
aggregationEndAtUtc = utcRange.endExclusiveUtc,
trigger = CreatorRankingSnapshotJobTrigger.SCHEDULED,
status = CreatorRankingSnapshotJobStatus.PENDING,
lastError = null,
processingStartedAt = null,
processedAt = null
)
)
val jobId = job.id ?: return
jobPort.markProcessing(jobId, LocalDateTime.now())
try {
refreshService.refreshLastCompletedWeek(now)
jobPort.markDone(jobId, LocalDateTime.now())
} catch (ex: Exception) {
jobPort.markFailed(jobId, LocalDateTime.now(), ex.message)
throw ex
}
}
}

View File

@@ -24,11 +24,6 @@ class CreatorRankingSnapshotRefreshService(
private val periodPolicy = CreatorRankingPeriodPolicy()
private val scorePolicy = CreatorRankingScorePolicy()
@Transactional
fun refreshLastCompletedWeek() {
refreshLastCompletedWeek(ZonedDateTime.now())
}
@Transactional
fun refreshLastCompletedWeek(now: ZonedDateTime) {
val startedAt = System.currentTimeMillis()