Skip to content

feat: 최대 집중시간 제한(3시간) 설정 및 좀비 세션 스케줄러 삭제#54

Merged
Juhye0k merged 3 commits intodevfrom
ip
Dec 4, 2025
Merged

feat: 최대 집중시간 제한(3시간) 설정 및 좀비 세션 스케줄러 삭제#54
Juhye0k merged 3 commits intodevfrom
ip

Conversation

@Juhye0k
Copy link
Copy Markdown
Contributor

@Juhye0k Juhye0k commented Dec 4, 2025

🚀 1. 개요

기존의 백그라운드 스케줄러를 이용한 좀비 세션 관리 방식을 제거하고, 클라이언트의 하트비트 요청 시점에최대 집중 시간을 검증하여 세션을 자동 종료하도록 로직을 변경했습니다.

📝 2. 주요 변경 사항

1. 좀비 세션 스케줄러 제거

  • 삭제: StudySessionSchedulerService.java
  • 서버 리소스를 점유하던 스케줄러 로직을 제거하고, 요청 기반(Lazy) 검증 방식으로 전환했습니다.

2. 최대 집중 시간(Max Focus Time) 로직 적용

  • StudySessionServiceMAX_FOCUS_TIME(3시간) 상수를 추가했습니다.
  • 하트비트 로직 변경 (updateHeartBeat):
    • 기존: 단순 시간 갱신 (void)
    • 변경: 시작 시간 기준 3시간 경과 여부 체크
      • 3시간 미만: 정상적으로 하트비트 시간 갱신, sessionActive: true 반환
      • 3시간 이상: 세션 강제 종료 처리, sessionActive: false 반환

Summary by CodeRabbit

릴리스 노트

  • 새로운 기능

    • 하트비트 응답에 세션 활성 여부와 메시지가 포함되어 상태를 즉시 확인할 수 있습니다.
    • 학습 세션의 최대 지속 시간이 3시간으로 설정되어, 초과 시 자동 종료됩니다.
  • 문서/표현 정렬

    • 관련 흐름 설명의 단계 표기와 문구가 정리·정렬되었습니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@Juhye0k Juhye0k self-assigned this Dec 4, 2025
@Juhye0k Juhye0k added the enhancement New feature or request label Dec 4, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 4, 2025

Walkthrough

심박수(heart-beat) 엔드포인트가 Void에서 HeartBeatResponse를 반환하도록 변경되고, 최대 집중 시간(MAX_FOCUS_TIME)을 3시간으로 강제하는 로직이 서비스에 추가되었으며, 좀비 세션 정리용 스케줄러 서비스가 삭제되었습니다.

Changes

Cohort / File(s) 변경 요약
API·컨트롤러 반환타입 변경
src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java, src/main/java/com/gpt/geumpumtabackend/study/controller/StudySessionController.java
processHeartBeat 반환 타입을 ResponseEntity<ResponseBody<Void>>ResponseEntity<ResponseBody<HeartBeatResponse>>로 변경; 컨트롤러가 서비스의 반환값을 바로 응답으로 래핑하도록 수정
HeartBeatResponse DTO 추가
src/main/java/com/gpt/geumpumtabackend/study/dto/response/HeartBeatResponse.java
새로운 레코드 HeartBeatResponse(boolean sessionActive, String message) 추가
서비스: 하트비트 로직 변경
src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java
updateHeartBeat 시그니처를 voidHeartBeatResponse로 변경; MAX_FOCUS_TIME = 3(시간) 상수 추가; 시작 시간으로부터 경과시간이 최대 집중 시간에 도달하면 세션 자동 종료 후 관련 응답 반환, 그렇지 않으면 마지막 심박 갱신 및 정상 응답 반환
스케줄러 제거
src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionSchedulerService.java
좀비 세션 정리용 스케줄러 클래스 파일 전체 삭제

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • 검토 포인트:
    • MAX_FOCUS_TIME 기준 계산(시간 단위, 경계값 처리)이 정확한지 확인
    • 세션 종료 시점(종료 시간을 startTime + MAX_FOCUS_TIME)과 관련 DB 업데이트/트랜잭션 처리 일관성
    • 컨트롤러·서비스·DTO 간 타입 변경에 따른 API 문서/클라이언트 영향 검증
    • 스케줄러 제거가 다른 컴포넌트(예: 테스트, 설정)에 미치는 영향

Possibly related PRs

Suggested reviewers

  • kon28289

Poem

🐇 깡충깡충 심장 소리 들려와,
세 시간의 집중 끝엔 문이 닫히네,
좀비 스케줄러는 쉬러 가고,
응답은 따끈한 메시지로 돌아오네 ✨
공부하는 날들, 토끼도 응원해요! 📚🐰

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 제목은 PR의 주요 변경사항을 명확하게 요약하고 있습니다: 최대 집중시간 제한 설정(3시간)과 좀비 세션 스케줄러 삭제라는 두 가지 핵심 변경을 간결하게 표현하고 있습니다.
Description check ✅ Passed PR 설명이 저장소의 템플릿을 준수하면서 필수 섹션(개요, 주요 변경 사항)을 모두 포함하고 있으며, 상세한 기술 정보를 포함하고 있습니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ip

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (2)
src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java (2)

35-35: 상수명을 더 명확하게 개선하는 것을 고려하세요.

MAX_FOCUS_TIME 상수가 시간 단위를 나타내지만 상수명만으로는 단위가 명확하지 않습니다.

다음과 같이 개선할 수 있습니다:

-    private static final Integer MAX_FOCUS_TIME = 3;
+    private static final Integer MAX_FOCUS_TIME_HOURS = 3;

그리고 Line 105에서도 이에 맞춰 변경:

-        if(elapsed.compareTo(Duration.ofHours(MAX_FOCUS_TIME)) >= 0) {
+        if(elapsed.compareTo(Duration.ofHours(MAX_FOCUS_TIME_HOURS)) >= 0) {

104-111: 최대 집중 시간 제한 로직이 올바르게 구현되었습니다.

3시간 제한 로직이 의도대로 구현되었습니다:

  • 세션 시작부터 현재까지의 경과 시간을 계산
  • 3시간 이상이면 세션을 시작 시점 + 3시간으로 종료 (소급 종료)
  • 적절한 HeartBeatResponse 반환

다만, 다음 개선 사항을 고려하세요:

  1. 하드코딩된 메시지를 i18n으로 관리: Line 107과 Line 110의 한글 메시지를 메시지 리소스 파일로 외부화하면 다국어 지원 및 유지보수성이 향상됩니다.

  2. 로깅 추가: 3시간 제한으로 세션이 자동 종료될 때 로그를 남기면 모니터링에 유용합니다.

         Duration elapsed = Duration.between(studySession.getStartTime(), LocalDateTime.now());
         if(elapsed.compareTo(Duration.ofHours(MAX_FOCUS_TIME)) >= 0) {
+            log.info("Session {} for user {} exceeded max focus time (3 hours), auto-terminating", sessionId, userId);
             studySession.endStudySession(studySession.getStartTime().plusHours(MAX_FOCUS_TIME));
             return new HeartBeatResponse(false, "최대 집중시간은 3시간입니다.");
         }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b9f8e5 and 408cc2c.

📒 Files selected for processing (5)
  • src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java (3 hunks)
  • src/main/java/com/gpt/geumpumtabackend/study/controller/StudySessionController.java (2 hunks)
  • src/main/java/com/gpt/geumpumtabackend/study/dto/response/HeartBeatResponse.java (1 hunks)
  • src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionSchedulerService.java (0 hunks)
  • src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionService.java (5 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/com/gpt/geumpumtabackend/study/service/StudySessionSchedulerService.java
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/gpt/geumpumtabackend/study/controller/StudySessionController.java (1)
src/main/java/com/gpt/geumpumtabackend/global/response/ResponseUtil.java (1)
  • ResponseUtil (5-28)
🔇 Additional comments (3)
src/main/java/com/gpt/geumpumtabackend/study/dto/response/HeartBeatResponse.java (1)

3-4: LGTM!

하트비트 응답을 위한 간결하고 명확한 record 타입입니다. sessionActive로 세션 상태를 전달하고 message로 상세 정보를 제공하는 구조가 적절합니다.

src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java (1)

173-173: API 반환 타입 변경을 확인하세요.

반환 타입이 ResponseBody<Void>에서 ResponseBody<HeartBeatResponse>로 변경되어 클라이언트가 이제 세션 상태(sessionActive)와 메시지를 받게 됩니다. 이는 의도된 breaking change이지만, 모든 클라이언트 구현체가 이 변경에 대응하도록 업데이트되었는지 확인이 필요합니다.

src/main/java/com/gpt/geumpumtabackend/study/controller/StudySessionController.java (1)

68-70: LGTM!

하트비트 엔드포인트가 이제 HeartBeatResponse를 반환하도록 올바르게 구현되었습니다. 서비스 계층의 반환값을 적절하게 감싸서 클라이언트에 전달합니다.

@Juhye0k Juhye0k requested a review from kon28289 December 4, 2025 05:56
…pi.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@kon28289 kon28289 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

@Juhye0k Juhye0k merged commit 9c54e85 into dev Dec 4, 2025
2 of 3 checks passed
Copy link
Copy Markdown
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java (2)

141-159: 하트비트 Javadoc에서 항목 1, 2가 중복되어 있습니다.

🔄 동작 원리 아래에서:

  • 149–150행에 1, 2번 항목이 있고
  • 151–152행에 동일한 1, 2번 항목이 한 번 더 반복됩니다.

문서 가독성을 위해 중복된 항목은 제거하고, 1–3번을 한 번만 나열하도록 정리하는 것이 좋겠습니다.

예시:

-            🔄 **동작 원리:**
-            1. Wi-Fi 연결 상태 재검증 (Gateway IP + IP 대역 확인)
-            2. 클라이언트 실제 IP 주소 재확인 (서버에서 추출)
-            1. Wi-Fi 연결 상태 재검증 (Gateway IP + IP 대역 확인)
-            2. 클라이언트 실제 IP 주소 재확인 (서버에서 추출)
-            3. 최대 집중 시간(3시간) 초과 여부 확인 및 자동 세션 종료
+            🔄 **동작 원리:**
+            1. Wi-Fi 연결 상태 재검증 (Gateway IP + IP 대역 확인)
+            2. 클라이언트 실제 IP 주소 재확인 (서버에서 추출)
+            3. 최대 집중 시간(3시간) 초과 여부 확인 및 자동 세션 종료

28-41: 90초 자동 종료 설명과 3시간 최대 집중 시간 설명을 한 번 더 정합성 체크해 주세요.

상단 ⚠️ 중요사항(38–40행)에는:

  • “하트비트 중단시 90초 후 자동 세션 종료”

라고 되어 있고, 하트비트 Javadoc(148–153행)에는:

  • “최대 집중 시간(3시간) 초과 여부 확인 및 자동 세션 종료”

가 추가되었습니다.

실제 백엔드 로직이 “하트비트 미수신 90초 타임아웃”과 “3시간 최대 집중 시간”을 둘 다 사용한다면, 두 제약이 함께 동작한다는 점을 명시해 주시면 좋고,
만약 기존 90초 타임아웃이 제거/완화되고 3시간 제한만 유효하다면, 40행의 90초 설명을 최신 동작에 맞게 수정하거나 삭제하는 편이 혼선을 줄일 수 있습니다.

Also applies to: 141-159

🧹 Nitpick comments (1)
src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java (1)

161-176: 하트비트 응답 타입을 Swagger 문서에도 명시하는 것을 고려해 주세요.

processHeartBeat의 실제 반환 타입이 ResponseEntity<ResponseBody<HeartBeatResponse>>로 변경되었는데,
@SwaggerApiSuccessResponse에서는 response 타입을 명시하지 않고 있습니다. 위쪽 getTodayStudySession, startStudySession과의 일관성을 위해 아래와 같이 응답 타입을 명시하면 Swagger 문서에서 스키마가 더 명확해질 것 같습니다.

예시:

-    @SwaggerApiResponses(
-            success = @SwaggerApiSuccessResponse(
-                    description = "하트비트 전송 성공 - 세션 유지"),
+    @SwaggerApiResponses(
+            success = @SwaggerApiSuccessResponse(
+                    response = HeartBeatResponse.class,
+                    description = "하트비트 전송 성공 - 세션 유지"),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 408cc2c and a29fdb1.

📒 Files selected for processing (1)
  • src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java (3 hunks)
⏰ 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: build
🔇 Additional comments (1)
src/main/java/com/gpt/geumpumtabackend/study/api/StudySessionApi.java (1)

12-13: HeartBeatResponse 도입 및 반환 타입 변경 방향은 적절해 보입니다.

  • HeartBeatResponse import 추가와
  • processHeartBeat의 반환 타입을 ResponseBody<HeartBeatResponse>로 바꾼 부분은 PR 설명(세션 활성/만료 여부를 응답으로 전달)에 잘 부합하고, API 사용성도 좋아졌습니다.

별다른 이슈 없어 보입니다.

Also applies to: 172-177

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants