Skip to content

Commit 8793b85

Browse files
committed
refactor(recruit-board): 스케쥴링 로직 리팩토링
- between()으로 변경
1 parent 373638b commit 8793b85

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/main/java/com/somemore/domains/recruitboard/repository/RecruitBoardRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface RecruitBoardRepository {
3636

3737
long updateRecruitingToClosedByStartDate(LocalDateTime startTime, LocalDateTime endTime);
3838

39-
long updateClosedToCompletedByEndDate(LocalDateTime now);
39+
long updateClosedToCompletedByEndDate(LocalDateTime startTime, LocalDateTime endTime);
4040

4141
// Page<RecruitBoardDetail> findAllNearbyWithKeyword(RecruitBoardNearByCondition condition);
4242
// Page<RecruitBoardWithCenter> findByRecruitBoardsContaining(RecruitBoardSearchCondition condition);

src/main/java/com/somemore/domains/recruitboard/repository/RecruitBoardRepositoryImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ public long updateRecruitingToClosedByStartDate(LocalDateTime startTime,
223223
}
224224

225225
@Override
226-
public long updateClosedToCompletedByEndDate(LocalDateTime now) {
226+
public long updateClosedToCompletedByEndDate(LocalDateTime startTime, LocalDateTime endTime) {
227227
return queryFactory.update(recruitBoard)
228228
.set(recruitBoard.recruitStatus, COMPLETED)
229229
.where(
230230
statusEq(CLOSED),
231-
volunteerEndDateTimeBefore(now),
231+
volunteerEndDateTimeBetween(startTime, endTime),
232232
isNotDeleted()
233233
)
234234
.execute();
@@ -389,8 +389,9 @@ private static BooleanExpression volunteerStartDateTimeBetween(LocalDateTime sta
389389
return recruitBoard.recruitmentInfo.volunteerStartDateTime.between(startTime, endTime);
390390
}
391391

392-
private static BooleanExpression volunteerEndDateTimeBefore(LocalDateTime now) {
393-
return recruitBoard.recruitmentInfo.volunteerEndDateTime.before(now);
392+
private static BooleanExpression volunteerEndDateTimeBetween(LocalDateTime startTime,
393+
LocalDateTime endTime) {
394+
return recruitBoard.recruitmentInfo.volunteerEndDateTime.between(startTime, endTime);
394395
}
395396

396397
private OrderSpecifier<?>[] toOrderSpecifiers(Sort sort) {

src/main/java/com/somemore/domains/recruitboard/scheduler/RecruitBoardStatusUpdateScheduler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public class RecruitBoardStatusUpdateScheduler {
2727
@Scheduled(cron = "0 0 0 * * ?")
2828
public void updateRecruitBoardStatusToClosed() {
2929
log.info("봉사 시작일에 해당하는 모집글 상태를 CLOSED로 변경하는 작업 시작");
30-
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
31-
LocalDateTime startOfNextDay = LocalDate.now().plusDays(1).atStartOfDay();
30+
LocalDateTime today = LocalDate.now().atStartOfDay();
31+
LocalDateTime tomorrow = today.plusDays(1);
3232

3333
try {
3434
long updatedCount = recruitBoardRepository.updateRecruitingToClosedByStartDate(
35-
startOfDay, startOfNextDay);
35+
today, tomorrow);
3636
log.info("총 {}개의 모집글 상태를 CLOSED로 변경 완료", updatedCount);
3737
} catch (Exception e) {
3838
log.error("봉사 시작일에 해당하는 모집글 상태를 CLOSED로 변경하는 중 오류 발생", e);
@@ -48,10 +48,11 @@ public void updateRecruitBoardStatusToClosed() {
4848
@Scheduled(cron = "0 0 0 * * ?")
4949
public void updateRecruitBoardStatusToCompleted() {
5050
log.info("봉사 종료일이 지난 모집글 상태를 COMPLETED로 변경하는 작업 시작");
51-
LocalDateTime now = LocalDateTime.now();
51+
LocalDateTime today = LocalDate.now().atStartOfDay();
52+
LocalDateTime yesterday = today.minusDays(1);
5253

5354
try {
54-
long updatedCount = recruitBoardRepository.updateClosedToCompletedByEndDate(now);
55+
long updatedCount = recruitBoardRepository.updateClosedToCompletedByEndDate(yesterday, today);
5556
log.info("총 {}개의 모집글 상태를 COMPLETED로 변경 완료", updatedCount);
5657
} catch (Exception e) {
5758
log.error("봉사 종료일이 지난 모집글 상태를 COMPLETED로 변경하는 중 오류 발생", e);

0 commit comments

Comments
 (0)