Skip to content

Refactor/311 : 메일 발송 실패 트랜잭션 별도 관리#423

Merged
crocusia merged 6 commits intodevfrom
refactor/311
Aug 29, 2025
Merged

Refactor/311 : 메일 발송 실패 트랜잭션 별도 관리#423
crocusia merged 6 commits intodevfrom
refactor/311

Conversation

@crocusia
Copy link
Member

@crocusia crocusia commented Aug 28, 2025

🔎 작업 내용

  • 청크 기반 트랜잭션으로 메일 성공 로그 저장, 메일 실패 로그는 별도 트랜잭션으로 저장하는 메서드 추가

🛠️ 변경 사항

  • 기존 flush로 저장하던 메일 로그가 배치에 더 적합한 트랜잭션 구성에 따라 저장됨

closed #311

Summary by CodeRabbit

  • 신기능
    • 이메일 발송 결과(성공/실패)를 체계적으로 기록하는 로직이 추가되어 이력 확인이 쉬워졌습니다.
    • 발송 성공/실패 로그가 안정적인 배치 처리 경로로 기록되어 가시성이 향상되었습니다.
  • 버그 수정
    • 일부 상황에서 이메일 발송 결과가 누락되거나 반영이 지연되던 현상을 개선했습니다.
    • 발송 실패 시 원인과 시점을 안정적으로 저장해 재발견이 용이해졌습니다.
  • 리팩터링
    • 이메일 로그 저장 흐름을 전용 서비스로 분리하여 안정성과 유지보수성을 향상했습니다.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Walkthrough

메일 로그 저장 로직을 직접 DB에 쓰던 방식을 배치 서비스로 위임하도록 변경. AOP MailLogAspectMailLogBatchService를 주입하고 실패는 saveFailLog(...)(REQUIRES_NEW), 성공은 saveSuccessLog(...)로 기록하도록 분기함. DLQ 동작은 유지됨.

Changes

Cohort / File(s) Summary
Aspect 리팩터링
cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java
MailLogBatchService 의존성 추가 및 생성자 시그니처 변경. 실패 시 saveFailLog(...) 호출, 성공 시 saveSuccessLog(...) 호출. 기존 직접 MailLogRepository 저장 로직 주석 처리. DLQ 전송 로직 유지.
배치 서비스 추가
cs25-batch/src/main/java/com/example/cs25batch/batch/service/MailLogBatchService.java
@Service 추가. saveFailLog(...)(트랜잭션 propagation = REQUIRES_NEW) 및 saveSuccessLog(...) 도입하여 MailLog 엔티티를 생성해 MailLogRepository.save(...) 호출.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant A as MailLogAspect
  participant S as MailLogBatchService
  participant R as Redis DLQ

  rect rgba(220,235,255,0.4)
  Note over A: 메일 전송 AOP 처리
  A->>A: 메일 전송 시도
  alt 전송 실패
    A->>S: saveFailLog(subscription, quiz, now, cause) [REQUIRES_NEW]
    A-->>R: DLQ 전송 (기존 동작 유지)
  else 전송 성공
    A->>S: saveSuccessLog(subscription, quiz, now)
  end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective (issue#) Addressed Explanation
배치 내 AOP에서 로그 저장을 별도 트랜잭션으로 분리 (#311) — 실패 케이스 분리
배치 내 AOP에서 로그 저장을 별도 트랜잭션으로 분리 (#311) — 모든(성공 포함) 로그에 별도 트랜잭션 적용 saveSuccessLog(...)에 propagation = REQUIRES_NEW가 적용되어 있지 않음

Possibly related PRs

Suggested reviewers

  • HeeMang-Lee
  • Kimyoonbeom
  • jong-0126

Poem

"깡충이는 기록을 모아요, 톡톡톡 —
실패는 따로 숨겨두고 새 트랜잭션에 콕,
성공은 배치에게 살포시 맡기고,
큐는 여전히 소중히 지키고,
깡충깡충, 로그는 안전히 쌓였네 🐇"

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 70faaad and 1ebf5c8.

📒 Files selected for processing (1)
  • cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/311

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java (1)

30-33: 불필요 의존성 제거 (MailLogRepository 미사용)

현재 mailLogRepository는 전혀 사용되지 않습니다. 제거해서 의존성, 테스트 부담을 줄이세요. 또한 Line 20의 StringRedisTemplate import도 미사용입니다.

-    private final MailLogRepository mailLogRepository;
     private final RedisStreamsClient redisClient;
cs25-batch/src/main/java/com/example/cs25batch/batch/service/MailLogBatchService.java (1)

35-46: 성공 로그 트랜잭션 전파 전략 확인

@Transactional(기본 REQUIRED)은 청크 트랜잭션에 합류합니다. 의도대로 “성공=청크 단위, 실패=분리”라면 OK입니다. 만약 성공 로그가 반드시 상위 트랜잭션 내에서만 저장되어야 한다면 Propagation.MANDATORY가 더 엄격합니다. 팀 컨벤션에 맞춰 선택하세요.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1e3a773 and 70faaad.

📒 Files selected for processing (2)
  • cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java (4 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/batch/service/MailLogBatchService.java (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: crocusia
PR: NBC-finalProject/CS25-BE#191
File: cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java:60-60
Timestamp: 2025-06-27T09:00:50.236Z
Learning: MailLogAspect에서 mailLogRepository.flush() 호출은 배치 처리의 청크 단위 트랜잭션과 비동기 처리 환경에서 MailLog의 즉시 영속화가 필요해서 추가된 것입니다. 재시도 로직이 실패한 메일 로그에 즉시 접근해야 하는 요구사항 때문에 필수적입니다.
📚 Learning: 2025-06-27T09:00:50.236Z
Learnt from: crocusia
PR: NBC-finalProject/CS25-BE#191
File: cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java:60-60
Timestamp: 2025-06-27T09:00:50.236Z
Learning: MailLogAspect에서 mailLogRepository.flush() 호출은 배치 처리의 청크 단위 트랜잭션과 비동기 처리 환경에서 MailLog의 즉시 영속화가 필요해서 추가된 것입니다. 재시도 로직이 실패한 메일 로그에 즉시 접근해야 하는 요구사항 때문에 필수적입니다.

Applied to files:

  • cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java
🔇 Additional comments (2)
cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java (1)

55-64: flush 제거 타당성 확인 — REQUIRES_NEW로 즉시 커밋 보장

이전 학습 맥락상 실패 로그의 즉시 영속화가 요구되었으나, 이제 실패 경로는 REQUIRES_NEW 트랜잭션으로 분리 저장되므로 커밋 시점이 보장됩니다. 주석 처리된 save/flush 제거는 일관된 설계입니다.

즉시 가용성을 검증하려면, DLQ 컨슈머가 실패 로그 조회 시점에 해당 레코드가 관측되는지 통합 테스트로 확인해 주세요(동일 쓰레드 내 saveFailLog 호출 직후 조회).

cs25-batch/src/main/java/com/example/cs25batch/batch/service/MailLogBatchService.java (1)

20-33: 실패 로그 REQUIRES_NEW 분리 트랜잭션 설계 적합

실패 로그를 별도 트랜잭션으로 커밋하여 상위 트랜잭션 롤백과 무관하게 보존하는 접근은 요구사항에 부합합니다. LGTM.

@crocusia crocusia merged commit dac136a into dev Aug 29, 2025
2 checks passed
@crocusia crocusia deleted the refactor/311 branch August 29, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

배치 내 AOP에서 Flush 사용

3 participants