Skip to content

Commit 8ac0a3d

Browse files
authored
fix: 보정 스케줄러의 미처리 요청 감지 범위 확장 (#226)
* fix: 보정 스케줄러의 미처리 요청 감지 범위 확장 * chore: 중복되는 주석 정리 * chore: PR 템플릿에 작업개요 및 버그/성능/문서/설정 유형 추가
1 parent 4f0b05d commit 8ac0a3d

3 files changed

Lines changed: 50 additions & 7 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
## 🛠️ 작업 내용
1+
## 🚀 작업 개요
2+
-
23

4+
## 🛠️ 작업 내용
5+
-
36

47
## ✅ PR 유형
8+
- [ ] 버그 수정
9+
- [ ] 성능 개선
510
- [x] 새로운 기능 추가
6-
- [x] CSS 등 사용자 UI 디자인 변경
711
- [x] 코드 리팩토링
812
- [x] 파일 혹은 폴더명 수정
13+
- [ ] 문서 수정
14+
- [ ] 설정 변경
915

1016
## ✅ Check List
1117
- [x] 코드가 정상적으로 컴파일되나요?
@@ -14,6 +20,6 @@
1420
- [x] Label을 지정했나요?
1521

1622
## 🔗 관련 이슈
17-
-
23+
1824

1925
## 💬 기타 참고 사항

src/main/java/com/threestar/trainus/domain/lesson/issue/LessonApplyConsumer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public Object execute(org.springframework.data.redis.core.RedisOperations operat
133133
}
134134
}
135135
} finally {
136-
// 작업 완료 후 각 레슨별로 이번 배치에서 처리한 개수만큼 Busy 카운터 감소
137-
// 작업 완료 후 각 레슨별로 마지막 처리 시점 기록
136+
// 작업 완료 후 각 레슨별로 이번 배치에서 처리한 개수만큼 Busy 카운터 감소, 마지막 처리 시점 기록
138137
Map<Long, Long> countsPerLesson = messages.stream()
139138
.collect(Collectors.groupingBy(ApplyMessage::lessonId, Collectors.counting()));
140139

src/main/java/com/threestar/trainus/domain/lesson/issue/LessonStockReconciliationScheduler.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class LessonStockReconciliationScheduler {
3939
@Scheduled(fixedRate = 30000)
4040
@SchedulerLock(name = "LessonStockReconciliation", lockAtMostFor = "25s", lockAtLeastFor = "20s")
4141
public void reconcileStock() {
42+
// 대기열 잔여 메세지 존재 시 연기 (Core Redis)
43+
if (hasWaitingRoomMessages()) {
44+
log.info("Waiting room still has messages. Postponing reconciliation.");
45+
return;
46+
}
47+
4248
// 미처리 메세지 존재 시 연기 (MQ Redis)
4349
if (hasStreamLag()) {
4450
log.info("Stream still has pending messages or backlog in MQ. Postponing reconciliation.");
@@ -134,6 +140,37 @@ public void reconcileStock() {
134140
log.info("Finished Smart Stock Reconciliation for {} lessons.", processedCount);
135141
}
136142

143+
// 미처리 메세지 확인 메서드 (Core Redis)
144+
private boolean hasWaitingRoomMessages() {
145+
String dirtySetKey = LessonApplyStreamConstant.DIRTY_SET_KEY;
146+
147+
// Dirty Set 확인 (Core Redis)
148+
java.util.Set<String> lessonIds = coreRedisTemplate.opsForSet().members(dirtySetKey);
149+
if (lessonIds == null || lessonIds.isEmpty()) {
150+
return false;
151+
}
152+
153+
for (String lessonIdStr : lessonIds) {
154+
try {
155+
Long lessonId = Long.valueOf(lessonIdStr);
156+
157+
// 레슨별 대기열 잔여 메세지 확인 (Core Redis)
158+
String waitingRoomKey = String.format(LessonApplyStreamConstant.WAITING_ROOM_KEY, lessonId);
159+
Long size = coreRedisTemplate.opsForZSet().size(waitingRoomKey);
160+
if (size != null && size > 0) {
161+
log.info("Waiting room still has messages. lessonId={}, size={}", lessonId, size);
162+
return true;
163+
}
164+
} catch (Exception e) {
165+
// 대기열 확인 실패 시 보수적으로 보정 연기
166+
log.warn("Failed to check waiting room for lesson [{}]: {}", lessonIdStr, e.getMessage());
167+
return true;
168+
}
169+
}
170+
171+
return false;
172+
}
173+
137174
// 미처리 메세지 확인 메서드 (MQ Redis)
138175
private boolean hasStreamLag() {
139176
try {
@@ -151,8 +188,9 @@ private boolean hasStreamLag() {
151188
return size != null && size > 0;
152189

153190
} catch (Exception e) {
154-
// 스트림이 없거나 초기 상태일 경우
155-
return false;
191+
// 스트림 상태 확인 실패 시 보수적으로 보정 연기
192+
log.warn("Failed to check stream lag. Postponing reconciliation: {}", e.getMessage());
193+
return true;
156194
}
157195
}
158196
}

0 commit comments

Comments
 (0)