-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SAMBAD-249] 질문 활성 및 비활성화 체크 스케줄러 추가, 질문 조회 로직 리팩토링
- Loading branch information
Showing
15 changed files
with
218 additions
and
141 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/org/depromeet/sambad/moring/common/config/SchedulingConfig.java
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.depromeet.sambad.moring.common.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public class SchedulingConfig { | ||
} |
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
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
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
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
71 changes: 71 additions & 0 deletions
71
...omeet/sambad/moring/meeting/question/application/MeetingQuestionStatusCheckScheduler.java
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.depromeet.sambad.moring.meeting.question.application; | ||
|
||
import static java.time.LocalDateTime.*; | ||
import static org.depromeet.sambad.moring.event.domain.EventType.*; | ||
import static org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestionStatus.*; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.sambad.moring.event.application.EventService; | ||
import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting; | ||
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class MeetingQuestionStatusCheckScheduler { | ||
|
||
private final MeetingQuestionRepository meetingQuestionRepository; | ||
private final EventService eventService; | ||
|
||
@Scheduled(fixedDelay = 1000 * 5) | ||
@Transactional | ||
public void inactivate() { | ||
// 활성 상태이지만 만료 시간이 지나 INACTIVE 상태가 되어야 하는 질문 목록 조회 | ||
List<MeetingQuestion> targets = meetingQuestionRepository.findAllByStatusAndExpiredAtBefore(ACTIVE, now()); | ||
|
||
// 질문 비활성화 처리 | ||
targets.forEach(MeetingQuestion::updateStatusToInactive); | ||
|
||
// 해당 모임의 다음 질문 활성화 처리 및 이벤트 발행 | ||
targets.stream() | ||
.map(MeetingQuestion::getMeeting) | ||
.forEach(this::activate); | ||
|
||
// 결과 로깅 | ||
logResults(targets); | ||
} | ||
|
||
private void activate(Meeting meeting) { | ||
Long meetingId = meeting.getId(); | ||
|
||
meetingQuestionRepository.findFirstByMeetingIdAndStatus(meetingId, NOT_STARTED) | ||
.ifPresent(targetMeetingQuestion -> { | ||
targetMeetingQuestion.updateStatusToActive(now()); | ||
reissueTargetMemberEvent(targetMeetingQuestion); | ||
log.info("Activated not started meeting question. {}", targetMeetingQuestion.getId()); | ||
}); | ||
} | ||
|
||
private void reissueTargetMemberEvent(MeetingQuestion target) { | ||
Long meetingId = target.getMeeting().getId(); | ||
Long targetMemberUserId = target.getTargetMember().getUser().getId(); | ||
|
||
eventService.inactivateLastEventsOfAllMemberByType(meetingId, QUESTION_REGISTERED); | ||
eventService.inactivateLastEventByType(targetMemberUserId, meetingId, TARGET_MEMBER); | ||
eventService.publish(targetMemberUserId, meetingId, TARGET_MEMBER); | ||
} | ||
|
||
private void logResults(List<MeetingQuestion> targets) { | ||
if (!targets.isEmpty()) { | ||
List<Long> inactivatedIds = targets.stream().map(MeetingQuestion::getId).toList(); | ||
log.info("Inactivated {} meeting questions. {}", targets.size(), inactivatedIds); | ||
} | ||
} | ||
} |
Oops, something went wrong.