Skip to content

[Refactoring] 배치 작업 트리거 수정 및 Reader 방식 변경#162

Open
kmchaejin wants to merge 48 commits intomainfrom
feat#161/batch
Open

[Refactoring] 배치 작업 트리거 수정 및 Reader 방식 변경#162
kmchaejin wants to merge 48 commits intomainfrom
feat#161/batch

Conversation

@kmchaejin
Copy link
Copy Markdown
Collaborator

@kmchaejin kmchaejin commented Aug 6, 2025

📌 관련 이슈

✨ 기능 요약

항목 내용
🆕 기능명 오픈런 게시글 close 처리하는 배치 작업 수정
🔍 목적 성능 개선
🛠️ 변경사항 reader 방식 변경 및 트리거 수행 시간 변경

📝 상세 내역

번호 내용
1️⃣ 10분 간격이 아닌 매일 새벽 4시에 한 번만 수행하도록 수정
2️⃣ cursor 방식에서 iterator 방식으로 수정

📸 포스트맨 캡처 사진

스크린샷 2025-08-06 오전 11 37 40

🙋‍♀️ 리뷰어 참고사항

cursor 방식보다 iterator 방식이 수행 소요 시간이나 CPU 사용량 측면에서 성능이 향상됩니다.
https://www.notion.so/teamsparta/2242dc3ef51480e7a6b8e542527aa316
하루에 close로 상태 변경할 데이터 수가 1만 건 이상일 가능성이 미미하여 cursor 방식을 사용하는 것은 불필요하다고 판단하여 iterator 방식으로 수정하였습니다.

운영 환경에서 10분마다 배치가 돌아가는 것도 성능에 영향을 미치기 때문에 10분 간격으로 수행하던 걸 매일 새벽 4시(서비스 이용자가 가장 적을 거 같은 시간)에 한 번만 수행하도록 트리거를 수정했습니다.

Summary by CodeRabbit

  • 새로운 기능

    • Prometheus 모니터링을 위한 의존성이 명시적으로 추가 및 업데이트되었습니다.
  • 버그 수정

    • 만료된 게시글 ID를 일괄로 조회하여 처리하는 방식으로 개선되어, 배치 성능과 안정성이 향상되었습니다.
  • 기타

    • 게시글 마감 배치 작업이 10분마다에서 매일 오전 4시로 실행 주기가 변경되었습니다.

kmchaejin added 30 commits June 9, 2025 12:22
@kmchaejin kmchaejin self-assigned this Aug 6, 2025
@kmchaejin kmchaejin added the Refactoring 리팩토 label Aug 6, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 6, 2025

Walkthrough

배치 작업의 트리거가 10분마다 실행되던 것에서 하루 한 번(04:00)에 실행되도록 변경되었습니다. 또한, Board ID를 읽어오는 Reader가 커서 방식에서 Iterator 방식으로 단순화되었으며, 관련 의존성도 build.gradle에 명시적으로 추가되었습니다.

Changes

Cohort / File(s) Change Summary
Batch Reader 리팩토링
src/main/java/com/example/taste/domain/board/batch/ClosingBoardBatchConfig.java
커서 기반 ItemReader에서 IteratorItemReader로 변경, 만료된 게시글 ID 전체를 한 번에 읽어오도록 수정 및 로그 변경
배치 트리거 스케줄 변경
src/main/java/com/example/taste/domain/board/batch/ClosingBoardQuartzConfig.java
크론 스케줄을 10분마다에서 하루 한 번(04:00)으로 변경
의존성 명시적 추가
build.gradle
Micrometer Prometheus registry 및 Prometheus metrics core 의존성 명시적 추가 및 버전 지정

Sequence Diagram(s)

sequenceDiagram
    participant QuartzScheduler
    participant ClosingBoardBatchConfig
    participant BoardService
    participant IteratorItemReader

    QuartzScheduler->>ClosingBoardBatchConfig: 트리거(매일 04:00)
    ClosingBoardBatchConfig->>BoardService: findExpiredTimeAttackBoardIds(TIMEATTACK)
    BoardService-->>ClosingBoardBatchConfig: 만료된 게시글 ID 리스트 반환
    ClosingBoardBatchConfig->>IteratorItemReader: 리스트 래핑
    IteratorItemReader-->>BatchJob: ID 순차 반환
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
트리거 시간 변경 (하루 1번 배치 작업 수행) (#161)
reader 방식 변경 (iterator 방식으로 변경) (#161)

Poem

새벽 네 시, 토끼는 깨어
배치가 똑똑, 한 번만 실행돼요
커서 대신 이터레이터로
ID 한 번에 쏙쏙 모아요
코드도 가볍고, 로그도 산뜻
오늘도 배치는 깔끔하게 굿! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46acc6b and db3454d.

📒 Files selected for processing (3)
  • build.gradle (1 hunks)
  • src/main/java/com/example/taste/domain/board/batch/ClosingBoardBatchConfig.java (2 hunks)
  • src/main/java/com/example/taste/domain/board/batch/ClosingBoardQuartzConfig.java (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: mo00ai
PR: mo00ai/your-my-taste#60
File: src/main/java/com/example/taste/domain/user/repository/UserJdbcRepository.java:14-17
Timestamp: 2025-06-09T05:58:14.063Z
Learning: mo00ai는 성능 최적화보다는 단계별 기술 진화를 선호한다. 현재 단계에서 기본 기능을 구현하고, 이후 Spring Batch 도입 시점에 성능 최적화를 진행하여 before/after 성능 비교를 통한 정량적 개선 효과를 측정하는 접근법을 선호한다.
Learnt from: Chaemin07
PR: mo00ai/your-my-taste#82
File: src/main/java/com/example/taste/domain/board/service/BoardService.java:0-0
Timestamp: 2025-06-15T15:10:27.636Z
Learning: BoardRepositoryImpl.findBoardListDtoByUserIdList 메서드의 성능 최적화가 완료되었습니다. 서브쿼리 방식에서 LEFT JOIN + GROUP BY 방식으로 변경하여 N+1 쿼리 문제를 해결했습니다.
Learnt from: kmchaejin
PR: mo00ai/your-my-taste#33
File: src/main/java/com/example/taste/domain/store/service/StoreBucketService.java:127-139
Timestamp: 2025-06-04T02:13:29.504Z
Learning: kmchaejin은 코드에서 검증 로직을 별도 메서드로 분리하여 재사용 가능하게 구조화하는 것을 선호합니다.
📚 Learning: spring batch 환경에서는 step 레벨에서 platformtransactionmanager를 통해 트랜잭션이 관리되므로, 개별 repository 메서드에 @Transac...
Learnt from: mo00ai
PR: mo00ai/your-my-taste#105
File: src/main/java/com/example/taste/domain/user/repository/UserRepositoryJooqCustomImpl.java:0-0
Timestamp: 2025-06-21T05:46:17.046Z
Learning: Spring Batch 환경에서는 step 레벨에서 PlatformTransactionManager를 통해 트랜잭션이 관리되므로, 개별 repository 메서드에 Transactional 어노테이션을 중복으로 추가할 필요가 없음. 배치 writer에서 트랜잭션 매니저를 통해 하나로 묶어서 처리함.

Applied to files:

  • src/main/java/com/example/taste/domain/board/batch/ClosingBoardBatchConfig.java
📚 Learning: boardrepositoryimpl.findboardlistdtobyuseridlist 메서드의 성능 최적화가 완료되었습니다. 서브쿼리 방식에서 left join + group b...
Learnt from: Chaemin07
PR: mo00ai/your-my-taste#82
File: src/main/java/com/example/taste/domain/board/service/BoardService.java:0-0
Timestamp: 2025-06-15T15:10:27.636Z
Learning: BoardRepositoryImpl.findBoardListDtoByUserIdList 메서드의 성능 최적화가 완료되었습니다. 서브쿼리 방식에서 LEFT JOIN + GROUP BY 방식으로 변경하여 N+1 쿼리 문제를 해결했습니다.

Applied to files:

  • src/main/java/com/example/taste/domain/board/batch/ClosingBoardBatchConfig.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: generate-jooq
🔇 Additional comments (3)
build.gradle (1)

120-121: Prometheus 의존성 업데이트가 적절합니다.

micrometer-registry-prometheus 버전을 명시적으로 지정하고 prometheus-metrics-core를 추가한 것은 메트릭 모니터링 개선을 위한 좋은 변경사항입니다. 배치 작업의 모니터링 강화에 도움이 될 것입니다.

src/main/java/com/example/taste/domain/board/batch/ClosingBoardQuartzConfig.java (1)

29-29: 배치 실행 주기 변경이 성능 최적화에 적합합니다.

10분마다 실행에서 매일 새벽 4시 실행으로 변경한 것은 피크 시간대 성능 영향을 최소화하는 좋은 접근입니다. 일일 오픈런 게시글 마감 건수를 고려할 때 적절한 실행 주기입니다.

src/main/java/com/example/taste/domain/board/batch/ClosingBoardBatchConfig.java (1)

154-162: Iterator 방식으로의 변경이 적절합니다.

일일 처리량이 10,000건 미만인 상황에서 모든 ID를 한 번에 조회하는 Iterator 방식은 커서 방식보다 효율적입니다. IteratorItemReader를 사용한 것도 Spring Batch의 표준 구현체를 활용한 좋은 선택입니다. debug 레벨로 ID 목록을 출력하는 것도 운영 환경에서 적절한 로깅 전략입니다.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat#161/batch

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactoring 리팩토

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactoring] 배치 작업 트리거 수정 및 Reader 방식 변경

1 participant