-
Notifications
You must be signed in to change notification settings - Fork 3
[fix] 스케줄러는 db를 참조하여 모집현황을 갱신한다 #401
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
Changes from all commits
7e56421
0d47e8f
9c27303
e13ff04
252b491
499953b
3736417
94fcf7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| package moadong.club.service; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.ZoneId; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.ZonedDateTime; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.temporal.ChronoUnit; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||||||||||||||||||||
| import moadong.club.entity.Club; | ||||||||||||||||||||||||||||||||||||||||||||||
| import moadong.club.entity.ClubRecruitmentInformation; | ||||||||||||||||||||||||||||||||||||||||||||||
| import moadong.club.enums.ClubRecruitmentStatus; | ||||||||||||||||||||||||||||||||||||||||||||||
| import moadong.club.repository.ClubRepository; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.scheduling.annotation.Scheduled; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.stereotype.Component; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @Component | ||||||||||||||||||||||||||||||||||||||||||||||
| @RequiredArgsConstructor | ||||||||||||||||||||||||||||||||||||||||||||||
| public class RecruitmentStateChecker { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private final ClubRepository clubRepository; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @Scheduled(fixedRate = 60 * 60 * 1000) // 5분마다 실행 | ||||||||||||||||||||||||||||||||||||||||||||||
| public void performTask() { | ||||||||||||||||||||||||||||||||||||||||||||||
| List<Club> clubs = clubRepository.findAll(); | ||||||||||||||||||||||||||||||||||||||||||||||
| for (Club club : clubs) { | ||||||||||||||||||||||||||||||||||||||||||||||
| ClubRecruitmentInformation recruitInfo = club.getClubRecruitmentInformation(); | ||||||||||||||||||||||||||||||||||||||||||||||
| ZonedDateTime recruitmentStartDate = recruitInfo.getRecruitmentStart(); | ||||||||||||||||||||||||||||||||||||||||||||||
| ZonedDateTime recruitmentEndDate = recruitInfo.getRecruitmentEnd(); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (recruitInfo.getClubRecruitmentStatus() == ClubRecruitmentStatus.ALWAYS) { | ||||||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (recruitmentStartDate != null && recruitmentEndDate != null) { | ||||||||||||||||||||||||||||||||||||||||||||||
| ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (now.isBefore(recruitmentStartDate)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| long between = ChronoUnit.DAYS.between(recruitmentStartDate, now); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (between <= 14) { | ||||||||||||||||||||||||||||||||||||||||||||||
| club.updateRecruitmentStatus(ClubRecruitmentStatus.UPCOMING); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| club.updateRecruitmentStatus(ClubRecruitmentStatus.CLOSED); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } else if (now.isAfter(recruitmentStartDate) && now.isBefore(recruitmentEndDate)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| club.updateRecruitmentStatus(ClubRecruitmentStatus.OPEN); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else if (now.isAfter(recruitmentEndDate)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| club.updateRecruitmentStatus(ClubRecruitmentStatus.CLOSED); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+44
Contributor
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. 날짜 비교 로직 버그 수정 필요 34번 라인의 날짜 차이 계산 로직에 버그가 있습니다. - long between = ChronoUnit.DAYS.between(recruitmentStartDate, now);
+ long between = ChronoUnit.DAYS.between(now, recruitmentStartDate);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| club.updateRecruitmentStatus(ClubRecruitmentStatus.CLOSED); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| clubRepository.save(club); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+50
Contributor
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. 🛠️ Refactor suggestion 예외 처리 추가 필요 DB 작업 중 발생할 수 있는 예외에 대한 처리가 없습니다. 스케줄링 작업은 백그라운드에서 실행되므로 예외 처리와 로깅이 특히 중요합니다. @Scheduled(fixedRate = 60 * 60 * 1000) // 1시간마다 실행
public void performTask() {
+ try {
List<Club> clubs = clubRepository.findAll();
for (Club club : clubs) {
// 기존 로직...
}
+ } catch (Exception e) {
+ // 로깅 프레임워크 사용 (예: SLF4J)
+ log.error("Club recruitment status update failed", e);
+ // 필요한 경우 알림 시스템에 통보
+ }
} |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
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.
🛠️ Refactor suggestion
스케줄링 태스크 성능 보장을 위한 조치 필요
스케줄링 메서드에 트랜잭션 관리가 없습니다. DB 작업을 포함하는 스케줄링 태스크에서는 트랜잭션 관리가 중요합니다. 또한, 모든 클럽을 한번에 가져오는 방식은 클럽 수가 많아질 경우 성능 이슈가 발생할 수 있습니다.
@Scheduled(fixedRate = 60 * 60 * 1000) // 5분마다 실행 + @Transactional public void performTask() { List<Club> clubs = clubRepository.findAll();추가적으로 페이징 처리를 고려해보세요: