Skip to content

Commit

Permalink
Merge pull request #178 from kookmin-sw/backend/develop/v3
Browse files Browse the repository at this point in the history
Backend/develop/v3
  • Loading branch information
J-Yong99 authored May 30, 2024
2 parents 92a032d + 4f05f7e commit a863a01
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public void run() {
}

// 매 한시간마다 분석요청
@Scheduled(cron = "0 0 * * * *")
public void run2() {
log.info("Analysis Scheduler is running");
try {
// 만약 분석중인 카드뷰가 하나라도 있는 경우
if (!cardViewRepository.findAllByRecordFileStatusIn(List.of("WAIT")).isEmpty()) {
cardViewService.getIncompleteCardViews();
}

} catch (Exception e) {
log.error("Failed to send notification");
}
}
// @Scheduled(cron = "0 0 * * * *")
// public void run2() {
// log.info("Analysis Scheduler is running");
// try {
// // 만약 분석중인 카드뷰가 하나라도 있는 경우
// if (!cardViewRepository.findAllByRecordFileStatusIn(List.of("WAIT")).isEmpty()) {
// cardViewService.getIncompleteCardViews();
// }
//
// } catch (Exception e) {
// log.error("Failed to send notification");
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class CardViewService {

public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throws InterruptedException {
// ec2가 켜져있는지 확인
if (awsService.isEc2Running()){
throw new RuntimeException("EC2 is already running");
}
awsService.turnOnOrOff("moment-ai-t4", true);
// if (awsService.isEc2Running()){
// throw new RuntimeException("EC2 is already running");
// }
// awsService.turnOnOrOff("moment-ai-t4", true);
log.info("EC2 trying to turn on");
while (!awsService.isEc2Running()){
log.info("sleep");
Expand All @@ -50,7 +50,7 @@ public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throw
// 분석 완료 카드뷰 개수를 유저별로 저장
Map<User, Integer> userCardViewCount = new HashMap<>();

sleep(31000);
// sleep(31000);
// 경과 시간 체크를 위한 시작 시간
long startTime = System.currentTimeMillis();
List<CardView> cards = cardViewRepository.findAllByRecordFileStatusIn(List.of("WAIT"));
Expand Down Expand Up @@ -115,16 +115,16 @@ public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throw
}
long endTime = System.currentTimeMillis();
log.info("AI model run time : " + (endTime - startTime) + "ms");
awsService.turnOnOrOff("moment-ai-t4", false);
// awsService.turnOnOrOff("moment-ai-t4", false);

// 분석한만큼 유저에게 알림을 전송
for (User user : userCardViewCount.keySet()){
notiService.sendFinishNoti(user, userCardViewCount.get(user));
}

while (awsService.isEc2Running()){
sleep(5000);
}
// while (awsService.isEc2Running()){
// sleep(5000);
// }
return SchedulerResponseDTO.AIModelRunResponseDTO.builder()
.failRecordNum(failRecordNum)
.successRecordNum(successRecordNum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ public void sendQuestionNoti(User user, String question) {
log.error("Failed to send notification to user {}", user.getId());
}
}
}
try {
ResponseEntity<Integer> ret = notiClient.pushMessage(
FcmSendDto.builder()
.token(user.getFirebaseToken())
.title("moment")
.body(question)
.build()
);
log.info("Notification sent to user {} with response {}", user.getId(), ret);
} catch (Exception e){
log.error("Failed to send notification to user {}", user.getId());
}else{
try {
ResponseEntity<Integer> ret = notiClient.pushMessage(
FcmSendDto.builder()
.token(user.getFirebaseToken())
.title("moment")
.body(question)
.build()
);
log.info("Notification sent to user {} with response {}", user.getId(), ret);
} catch (Exception e){
log.error("Failed to send notification to user {}", user.getId());
}
}
}

Expand Down

0 comments on commit a863a01

Please sign in to comment.