-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] 스케줄러 의도대로 동작하지 않는 버그 수정 (#143) #144
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,38 +49,44 @@ public void registerFcfsEvents() { | |
// redis에 저장된 모든 선착순 이벤트의 당첨자 정보를 DB로 이관 | ||
@Transactional | ||
public void registerWinners() { | ||
Set<String> fcfsIds = stringRedisTemplate.keys("*:count"); | ||
if (fcfsIds == null || fcfsIds.isEmpty()) { | ||
Set<String> fcfsKeys = stringRedisTemplate.keys("*:count"); | ||
if (fcfsKeys == null || fcfsKeys.isEmpty()) { | ||
log.info("There are no FCFS events in yesterday"); | ||
return; | ||
} | ||
|
||
for(String fcfsId : fcfsIds) { | ||
String eventId = fcfsId.replace(":count", "").replace("fcfs:", ""); | ||
Set<String> userIds = stringRedisTemplate.opsForZSet().range(FcfsUtil.winnerFormatting(eventId), 0, -1); | ||
// 당첨자 관련 정보 조합하여 Entity 생성 | ||
log.info("keys for FCFS Events: {}", fcfsKeys); | ||
for(String key : fcfsKeys) { | ||
String fcfsEventId = key.replace(":count", "").replace("fcfs:", ""); | ||
Set<String> userIds = stringRedisTemplate.opsForZSet().range(FcfsUtil.winnerFormatting(fcfsEventId), 0, -1); | ||
if(userIds == null || userIds.isEmpty()) { | ||
return; | ||
log.info("No winners in FCFS Event {}", fcfsEventId); | ||
continue; | ||
} | ||
|
||
FcfsEvent event = fcfsEventRepository.findById(Long.parseLong(eventId)) | ||
FcfsEvent event = fcfsEventRepository.findById(Long.parseLong(fcfsEventId)) | ||
.orElseThrow(() -> new FcfsEventException(ErrorCode.FCFS_EVENT_NOT_FOUND)); | ||
|
||
List<EventUser> users = eventUserRepository.findAllByUserId(userIds.stream().toList()); | ||
List<FcfsEventWinningInfo> winningInfos = users | ||
.stream() | ||
.map(user -> FcfsEventWinningInfo.of(event, user, getTimeFromScore(stringRedisTemplate.opsForZSet().score(FcfsUtil.winnerFormatting(eventId), user.getUserId())))) | ||
.map(user -> FcfsEventWinningInfo.of(event, user, getTimeFromScore(stringRedisTemplate.opsForZSet().score(FcfsUtil.winnerFormatting(fcfsEventId), user.getUserId())))) | ||
Comment on lines
-64
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그 외 eventId라는 표현이 모호하다고 생각하여 fcfsEventId로 표현을 명확하게 다듬었습니다. |
||
.toList(); | ||
|
||
log.info("Winners of FCFS event {} were registered in DB", fcfsEventId); | ||
fcfsEventWinningInfoRepository.saveAll(winningInfos); | ||
deleteEventInfo(eventId); | ||
deleteEventInfo(fcfsEventId); | ||
} | ||
|
||
// PK를 간접적으로 보관하던 eventId 제거 | ||
Set<String> eventIds = stringRedisTemplate.keys("*:eventId"); | ||
if(eventIds != null && !eventIds.isEmpty()) { | ||
for(String eventId : eventIds) { | ||
stringRedisTemplate.delete(eventId); | ||
} | ||
} | ||
log.info("Winners of all FCFS events were registered in DB"); | ||
log.info("Registering winners of FCFS events in DB is completed"); | ||
} | ||
|
||
// 특정 선착순 이벤트의 정보 조회 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존 return;으로 인해 운이 좋지 않게도 앞 순번의 선착순 이벤트의 당첨자가 없는 경우 메서드 자체가 종료되어 버리기에 뒤에 서있던 다른 선착순 이벤트의 결과 정보가 DB로 이동하지 못하고 붕 떠버리고 있었습니다.
continue로 바꾸어 뒷 순번 이벤트 결과도 저장할 수 있도록 고친 결과 정상 동작합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
시연 이전에 예외를 찾을 수 있어서 다행이네요. 생각보다 심각한 버그일 수 있었는데 수정해서 다행입니다.