Repository navigation
[fix] AI 답글 스케줄링을 AFTER_COMMIT 이벤트로 분리하여 댓글 트랜잭션 보호 #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/daramg/server/aicomment/event/AiReplyScheduleEvent.java
This file contains hidden or 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,7 @@ | ||
| package com.daramg.server.aicomment.event; | ||
|
|
||
| public record AiReplyScheduleEvent( | ||
| Long aiCommentId, | ||
| Long postId | ||
| ) { | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/daramg/server/aicomment/event/AiReplyScheduleEventListener.java
This file contains hidden or 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 com.daramg.server.aicomment.event; | ||
|
|
||
| import com.daramg.server.aicomment.application.AiCommentService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.event.TransactionalEventListener; | ||
|
|
||
| import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AiReplyScheduleEventListener { | ||
|
|
||
| private final AiCommentService aiCommentService; | ||
|
|
||
| @TransactionalEventListener(phase = AFTER_COMMIT) | ||
| public void handleAiReplyScheduleEvent(AiReplyScheduleEvent event) { | ||
| try { | ||
| aiCommentService.scheduleReplyForAiComment(event.aiCommentId(), event.postId()); | ||
| } catch (Exception e) { | ||
| log.warn("AI 답글 잡 등록 실패 - aiCommentId={}, postId={}", event.aiCommentId(), event.postId(), e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AiReplyScheduleEvent와 이 메서드에서postId를 별도로 전달받고 있으나,aiComment.getPost()를 통해 이미 해당 엔티티에 접근할 수 있습니다. 이벤트를 발행할 때aiCommentId만 전달하고 서비스 내부에서aiComment.getPost()를 활용하면, 이벤트 객체와 메서드 시그니처를 더 간결하게 유지할 수 있습니다.