-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1e64e43
commit c795255
Showing
24 changed files
with
335 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package kr.galaxyhub.sc.common.config | ||
|
||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.scheduling.annotation.EnableAsync | ||
|
||
@EnableAsync | ||
@Configuration | ||
class AsyncConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/main/kotlin/kr/galaxyhub/sc/news/application/dto/NewsAppendContentEvent.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...kotlin/kr/galaxyhub/sc/translation/application/TranslateProgressionStatusChangeService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kr.galaxyhub.sc.translation.application | ||
|
||
import java.util.UUID | ||
import kr.galaxyhub.sc.translation.domain.TranslateProgressionRepository | ||
import kr.galaxyhub.sc.translation.domain.getOrThrow | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@Transactional | ||
class TranslateProgressionStatusChangeService( | ||
private val translateProgressionRepository: TranslateProgressionRepository, | ||
) { | ||
|
||
fun changeComplete(translateProgressionId: UUID) { | ||
val translateProgression = translateProgressionRepository.getOrThrow(translateProgressionId) | ||
translateProgression.changeComplete() | ||
} | ||
|
||
fun changeFailure(translateProgressionId: UUID, message: String?) { | ||
val translateProgression = translateProgressionRepository.getOrThrow(translateProgressionId) | ||
translateProgression.changeFailure(message) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/kr/galaxyhub/sc/translation/application/TranslateResultEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package kr.galaxyhub.sc.translation.application | ||
|
||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import java.util.UUID | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Component | ||
|
||
private val log = KotlinLogging.logger {} | ||
|
||
/** | ||
* TranslationCommandService.translate 메서드의 트랜잭션이 API 호출보다 늦게 끝나면 예외 발생 가능성 있음. | ||
* 따라서 log를 error로 발생시킴 | ||
* 해당 로그 파악하면 Retry 전략 구성할 것 | ||
* 혹은 TranslationCommandService.translate에서 TransactionalEventListener를 받는곳에서 WebClient 실행 고려 | ||
*/ | ||
@Component | ||
class TranslateResultEventListener( | ||
private val translateProgressionStatusChangeService: TranslateProgressionStatusChangeService, | ||
) { | ||
|
||
@Async | ||
@EventListener | ||
fun translateSuccessEventHandler(event: TranslateSuccessEvent) { | ||
try { | ||
translateProgressionStatusChangeService.changeComplete(event.translateProgressionId) | ||
} catch (e: Exception) { | ||
log.error { "번역 진행 상황의 상태를 변경 중 예외가 발생했습니다. message=${e.message}" } | ||
} | ||
} | ||
|
||
@Async | ||
@EventListener | ||
fun translateFailureEventHandler(event: TranslateFailureEvent) { | ||
try { | ||
translateProgressionStatusChangeService.changeFailure(event.translateProgressionId, event.message) | ||
} catch (e: Exception) { | ||
log.error { "번역 진행 상황의 상태를 변경 중 예외가 발생했습니다. message=${e.message}" } | ||
} | ||
} | ||
} | ||
|
||
data class TranslateSuccessEvent( | ||
val translateProgressionId: UUID, | ||
) | ||
|
||
data class TranslateFailureEvent( | ||
val translateProgressionId: UUID, | ||
val message: String?, | ||
) | ||
|
48 changes: 0 additions & 48 deletions
48
...n/kotlin/kr/galaxyhub/sc/translation/application/TranslationAppendContentEventListener.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/kr/galaxyhub/sc/translation/application/TranslatorClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package kr.galaxyhub.sc.translation.application | ||
|
||
import kr.galaxyhub.sc.news.domain.Language | ||
import kr.galaxyhub.sc.news.domain.NewsInformation | ||
import kr.galaxyhub.sc.translation.domain.TranslatorProvider | ||
import reactor.core.publisher.Mono | ||
|
||
interface TranslatorClient { | ||
|
||
fun requestTranslate(request: TranslatorClientRequest): Mono<TranslatorClientResponse> | ||
|
||
fun getProvider(): TranslatorProvider | ||
} | ||
|
||
data class TranslatorClientRequest( | ||
val newsInformation: NewsInformation, | ||
val content: String, | ||
val sourceLanguage: Language, | ||
val targetLanguage: Language, | ||
) | ||
|
||
data class TranslatorClientResponse( | ||
val newsInformation: NewsInformation, | ||
val content: String, | ||
val language: Language | ||
) |
3 changes: 2 additions & 1 deletion
3
...c/translation/domain/TranslatorClients.kt → ...nslation/application/TranslatorClients.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
src/main/kotlin/kr/galaxyhub/sc/translation/application/dto/TranslationCommand.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/main/kotlin/kr/galaxyhub/sc/translation/application/dto/TranslatorFailureEvent.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.