Skip to content

Refactor/338 : Redis와 상호작용 모듈화, ACK 시점 변경, 문제 출제 실패 시 메시지 삭제 추가#421

Merged
crocusia merged 12 commits intodevfrom
refactor/338
Aug 21, 2025
Merged

Refactor/338 : Redis와 상호작용 모듈화, ACK 시점 변경, 문제 출제 실패 시 메시지 삭제 추가#421
crocusia merged 12 commits intodevfrom
refactor/338

Conversation

@crocusia
Copy link
Copy Markdown
Member

@crocusia crocusia commented Aug 21, 2025

🔎 작업 내용

  • Reader에서 ACK하던 것을 Writer 시점으로 변경
  • 문제 출제 실패 시에도 ACK 및 DEL하도록 변경

🛠️ 변경 사항

  • RedisStreamsClient 생성 후 reader, processor, writer에 적용

Summary by CodeRabbit

  • 신규 기능
    • 메일 상태에 QUIZ_FAILED 추가로 실패 유형을 더 명확히 식별 가능
  • 개선
    • 메일 전송 실패 시 재처리/격리(DLQ) 흐름 강화로 안정성 향상
    • 전송 속도 제어 정책 조정(동일 TPS 유지, 버스트 특성 개선)으로 처리 균형성 향상
  • 리팩터링
    • Redis 스트림 처리 로직을 전용 클라이언트로 통합해 읽기·확인·삭제 흐름 단순화
    • 메일 전송 전략 인터페이스를 소비 여부 반환 방식으로 일원화해 사용성 개선

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

RedisStreamsClient abstraction is added and wired via RedisStreamsConfig. Multiple components (reader, writer, aspect, processor) are refactored to use it for read/ack/delete/DLQ. Mail sending rate-limiter API changes from getBucket() to tryConsume(). MailStatus enum gains QUIZ_FAILED.

Changes

Cohort / File(s) Summary
Redis Streams Client introduction
cs25-batch/.../adapter/RedisStreamsClient.java, cs25-batch/.../config/RedisStreamsConfig.java, cs25-batch/.../aop/MailLogAspect.java, cs25-batch/.../batch/component/reader/RedisStreamReader.java, cs25-batch/.../batch/component/writer/MailWriter.java, cs25-batch/.../batch/component/processor/MailConsumerAsyncProcessor.java
New RedisStreamsClient wrapper; Spring bean configured for quiz-email stream/group/consumer. Reader now uses readWithConsumerGroup and drops manual ack. Writer uses ackAndDel. Aspect uses addDlq. Processor uses ackAndDel on QuizException.
Rate limiter API change
cs25-batch/.../sender/MailSenderStrategy.java, cs25-batch/.../sender/JavaMailSenderStrategy.java, cs25-batch/.../sender/SesMailSenderStrategy.java, cs25-batch/.../sender/context/MailSenderContext.java, cs25-batch/.../batch/component/reader/RedisStreamReader.java
Replace getBucket() with tryConsume(Long). Adjust implementations and context to delegate to tryConsume. Update refill policies (same throughput, different window). Reader uses mailSenderContext.tryConsume(strategyKey, 1L).
Domain enum update
cs25-entity/.../mail/enums/MailStatus.java
Add enum constant QUIZ_FAILED.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant RS as RedisStreamsClient
  participant R as RedisStreamReader
  participant C as MailConsumerAsyncProcessor
  participant W as MailWriter
  participant DLQ as DLQ Stream

  R->>RS: readWithConsumerGroup(blockTimeout)
  alt message available
    RS-->>R: MapRecord (recordId, payload)
    R->>R: mailSenderContext.tryConsume(strategyKey, 1)
    alt rate-limit ok
      R-->>C: Subscription + recordId
      C->>C: getTodayQuizBySubscription()
      alt QuizException
        C->>RS: ackAndDel(recordId)
        C-->>W: null (skip)
      else Success
        C-->>W: MailDto(recordId, quiz)
        W->>W: sendMail()
        opt finally
          W->>RS: ackAndDel(recordId)
        end
      end
    else throttled
      R-->>C: null (skip)
    end
  else none
    RS-->>R: null
  end

  note over C,DLQ: On send failure in MailLogAspect, enqueue retry via redisClient.addDlq(...)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • HeeMang-Lee
  • Kimyoonbeom
  • wannabeing
  • jong-0126

Poem

토끼는 귀 쫑긋, 스트림 위를 달려가,
레디스 강 건너 편—깃발엔 ACK와 DEL이야.
버킷은 사라지고, 한 입씩 “tryConsume” 냠!
퀴즈가 비틀거리면 DLQ에 살포시 얌-
오늘도 메일꽃, 딸깍딸깍 봄처럼 활짝! 🐇✉️

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 264ebd5 and a1c9f9f.

📒 Files selected for processing (11)
  • cs25-batch/src/main/java/com/example/cs25batch/adapter/RedisStreamsClient.java (1 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java (3 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/batch/component/processor/MailConsumerAsyncProcessor.java (3 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/batch/component/reader/RedisStreamReader.java (2 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/batch/component/writer/MailWriter.java (3 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/config/RedisStreamsConfig.java (1 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/sender/JavaMailSenderStrategy.java (2 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/sender/MailSenderStrategy.java (1 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/sender/SesMailSenderStrategy.java (2 hunks)
  • cs25-batch/src/main/java/com/example/cs25batch/sender/context/MailSenderContext.java (1 hunks)
  • cs25-entity/src/main/java/com/example/cs25entity/domain/mail/enums/MailStatus.java (1 hunks)
✨ 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/338

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 @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai 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 @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @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
Copy Markdown
Collaborator

@Kimyoonbeom Kimyoonbeom left a comment

Choose a reason for hiding this comment

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


\
\ /
( )
.( o ).

@crocusia crocusia merged commit 1e3a773 into dev Aug 21, 2025
1 of 2 checks passed
@crocusia crocusia deleted the refactor/338 branch August 21, 2025 08:39
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.

3 participants