fix(i18n): 번역 작업을 1초 주기로 처리하고 실패 작업을 재개한다
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package kr.co.vividnext.sodalive.i18n.translation
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Modifying
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
import java.time.LocalDateTime
|
||||
@@ -14,6 +15,27 @@ interface TranslationJobRepository : JpaRepository<TranslationJob, Long> {
|
||||
sourceHash: String
|
||||
): TranslationJob?
|
||||
|
||||
fun findByResourceTypeAndResourceIdInAndTargetLanguageAndStatus(
|
||||
resourceType: LanguageTranslationTargetType,
|
||||
resourceIds: Collection<Long>,
|
||||
targetLanguage: String,
|
||||
status: TranslationJobStatus
|
||||
): List<TranslationJob>
|
||||
|
||||
@Modifying
|
||||
@Query(
|
||||
"""
|
||||
update TranslationJob j
|
||||
set j.status = kr.co.vividnext.sodalive.i18n.translation.TranslationJobStatus.PENDING,
|
||||
j.retryCount = 0,
|
||||
j.lastErrorMessage = null,
|
||||
j.nextRetryAt = :now
|
||||
where j.id = :jobId
|
||||
and j.status = kr.co.vividnext.sodalive.i18n.translation.TranslationJobStatus.FAILED
|
||||
"""
|
||||
)
|
||||
fun restartFailedJob(@Param("jobId") jobId: Long, @Param("now") now: LocalDateTime): Int
|
||||
|
||||
@Query(
|
||||
"""
|
||||
select j from TranslationJob j
|
||||
|
||||
+6
-1
@@ -34,7 +34,12 @@ class TranslationJobScheduler(
|
||||
targetLanguage = normalizedTargetLanguage,
|
||||
sourceHash = sourceHash
|
||||
)
|
||||
if (existingJob != null) return
|
||||
if (existingJob != null) {
|
||||
if (existingJob.status == TranslationJobStatus.FAILED && existingJob.sourceLanguage == normalizedSourceLanguage) {
|
||||
translationJobRepository.restartFailedJob(existingJob.id!!, LocalDateTime.now())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
translationJobRepository.save(
|
||||
TranslationJob(
|
||||
|
||||
@@ -18,7 +18,7 @@ class TranslationJobWorker(
|
||||
private val log = LoggerFactory.getLogger(javaClass)
|
||||
private val transactionTemplate = TransactionTemplate(transactionManager)
|
||||
|
||||
@Scheduled(fixedDelayString = "\${sodalive.translation-job.fixed-delay-ms:600000}")
|
||||
@Scheduled(fixedDelayString = "\${sodalive.translation-job.fixed-delay-ms:1000}")
|
||||
fun runPendingJobs() {
|
||||
repeat(MAX_GROUPS_PER_TICK) {
|
||||
if (!processNextGroup()) return
|
||||
@@ -121,7 +121,7 @@ class TranslationJobWorker(
|
||||
val job = translationJobRepository.findById(jobId).orElse(null) ?: return@executeWithoutResult
|
||||
job.retryCount += 1
|
||||
job.lastErrorMessage = ex.message?.take(MAX_ERROR_LENGTH)
|
||||
if (job.retryCount >= MAX_RETRY_COUNT) {
|
||||
if (job.retryCount >= MAX_ATTEMPTS) {
|
||||
job.status = TranslationJobStatus.FAILED
|
||||
} else {
|
||||
job.status = TranslationJobStatus.PENDING
|
||||
@@ -142,6 +142,6 @@ class TranslationJobWorker(
|
||||
companion object {
|
||||
private const val MAX_GROUPS_PER_TICK = 5
|
||||
private const val MAX_ERROR_LENGTH = 1000
|
||||
private const val MAX_RETRY_COUNT = 3
|
||||
private const val MAX_ATTEMPTS = 6
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user